image-size / image-size

Node module for detecting image dimensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

width and height are swapped for some iPhone photos

codyng opened this issue · comments

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??

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;
                    }
                }
            }

@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.