width and height are swapped for some iPhone photos
codyng opened this issue · comments
Cody Ng commented
I've tried to upload some photos taken with iPhone.
The returned width and height values are swapped after calling this package.
I think it may be the portrait or landscape issue.
Does anyone has this issue??
Cody Ng commented
Just find a solution.
We can find its orientation by using this library.
https://www.npmjs.com/package/@ginpei/exif-orientation
if (ext === 'jpg') {
const buffer = fs.readFileSync(file.path);
const orientation = await exif.getOrientation(buffer);
if (orientation !== null) {
if (orientation.rotation === 90 || orientation.rotation === 270) {
const w = dimension.width;
dimension.width = dimension.height;
dimension.height = w;
}
}
}
कारतोफ्फेलस्क्रिप्ट™ commented
@codyng this package also returns raw EXIF orientation value for jpegs.
you can see the test here https://github.com/image-size/image-size/blob/master/specs/valid.spec.ts#L87
if you need more info to map the raw values to more-readable angles, please let me know. I can document that in the readme.