Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotation and flip bug? #11

Closed
dlednik opened this issue Nov 22, 2018 · 4 comments
Closed

Rotation and flip bug? #11

dlednik opened this issue Nov 22, 2018 · 4 comments
Labels

Comments

@dlednik
Copy link

dlednik commented Nov 22, 2018

I tried using this lib in nodejs project as I need to add images to PDF document. I had issues with images that had rotation defined in EXIF metadata. So I tested this lib with images from https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto

I used their images that are for testing in their git repo.

I see issues with orientations 5 and 7:
EXIF_Content_A5_xmas.pdf

How images are saved back to file once callback is called:
image

@dlednik
Copy link
Author

dlednik commented Nov 22, 2018

@johansatge any idea what is going on? I need fix for this asap and are willing to fix the source code my self if you give me some pointers where to start 👍

@dlednik
Copy link
Author

dlednik commented Nov 22, 2018

quick workaround with sharp library if anyone needs it

if (orientation > 1) {
    if (orientation === 5 || orientation === 7) {
        // Until auto-rotate is fixed
        if (orientation === 5) {
            sharp(filePath).rotate(-90).flip().toBuffer().then( data => {
                fs.writeFileSync(filePath, data);
            }).catch( err => {
                Helper.returnError(res, err, 400, `api_v1_photo:get/${req.params.orderId}/${req.params.photoId}`);
            });
        } else {
            sharp(filePath).rotate(90).flip().toBuffer().then( data => {
                fs.writeFileSync(filePath, data);
            }).catch( err => {
                Helper.returnError(res, err, 400, `api_v1_photo:get/${req.params.orderId}/${req.params.photoId}`);
            });
        }
    } else {
        fs.writeFileSync(filePath, buffer);
    }
}

@johansatge
Copy link
Owner

johansatge commented Nov 28, 2018

Hi,

thanks a lot for reporting this.

I reproduce too with the images from the /test/samples directory. It looks like the issue has been here for some time, unfortunately.

I had a quick look in src/transform.js and didn't see what's wrong. I will analyze the issue deeper in the next days. Before next week hopefully.

Note, this issue demonstrates that the existing tests are clearly not covering this module's features correctly. I have opened #12 to try to address this.

@johansatge johansatge added the bug label Nov 29, 2018
@johansatge johansatge mentioned this issue Nov 29, 2018
@johansatge
Copy link
Owner

Found the issue (pull request). When flipping the pixels to fix orientations 5 and 7, the destination width and height were wrong. That's why the destination image was broken.

The fix has been pushed in jpeg-autorotate@4.0.1.

Let's close this. Please feel free to reopen if you still have issues. Thanks again for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants