Skip to content

Instantly share code, notes, and snippets.

@scf37
scf37 / imageOrientation.ts
Last active September 5, 2023 16:43
Rotate image preview to compensate for EXIF orientation (Javascript / Typescript)
// Based on: https://stackoverflow.com/a/46814952/283851
// Based on: https://gist.github.com/mindplay-dk/72f47c1a570e870a375bd3dbcb9328fb
/**
* Create a Base64 Image URL, with rotation applied to compensate for EXIF orientation, if needed.
*
* Optionally resize to a smaller maximum width - to improve performance for larger image thumbnails.
*/
export function getImageUrl(file: File, maxWidth: number|undefined): Promise<string> {
return readOrientation(file).then(orientation => {