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

rotate().extract() resulting in bad extract area for iOS images rotated by metadata #4077

Closed
3 tasks done
setrol opened this issue Apr 22, 2024 · 2 comments
Closed
3 tasks done
Labels

Comments

@setrol
Copy link

setrol commented Apr 22, 2024

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • Running npm install sharp completes without error.
  • Running node -e "require('sharp')" completes without error.

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

  • I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

  System:
    OS: Linux 6.6 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 13.14 GB / 15.37 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 20.8.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.1.0 - /usr/local/bin/npm
  npmPackages:
    sharp: 0.33.3 => 0.33.3 

What are the steps to reproduce?

when doing a rotate().extract() on a image that origins from iOS and got rotated the extract function does not honour the attempted orientation fix that should happen calling the rotate() function but results in a bad extraction area error.

What is the expected behaviour?

the extract function should honour the rotation fix for iOS pictures that stored their rotations within their metadata.

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

const sharpStream = sharp(bufferInput, { failOn: 'none' });
sharpStream.rotate().extract({
      left: 287,
      top: 575,
      width: 3583,
      height: 1116,
    })
sharpStream.toBuffer();

where the rotation and extraction done separate work as expected:

let sharpStream = sharp(bufferInput, { failOn: 'none' });
sharpStream.rotate();
sharpStream = sharp(await sharpStream.toBuffer(), { failOn: 'none' });
sharpStream.extract({
      left: 287,
      top: 575,
      width: 3583,
      height: 1116,
    })
sharpStream.toBuffer();

Please provide sample image(s) that help explain this problem

the image provided within #4059 shows this behaviour.
Also https://assets-tt-com.nmo.at/im-content/images/3b6073d7-d32f-53a2-8c09-544729a6d408

the following one needs a narrower extract area:

{ width: 1583, height: 1116, left: 287, top: 575 }

https://assets-tt-com-events.production.tt.nmo.at/914aeac27bd6583117a06cf88c80096bca64fd38_Leob_hne_-_Schick_mir_keine_Blumen_-_Hochformat.jpeg

@setrol setrol added the triage label Apr 22, 2024
@lovell lovell added question and removed triage labels Apr 22, 2024
@lovell
Copy link
Owner

lovell commented Apr 22, 2024

Using the sample image from #4059 and the image from https://assets-tt-com.nmo.at/im-content/images/3b6073d7-d32f-53a2-8c09-544729a6d408, which are both 4032x3024 landscape images, I see exactly the same extract_area: bad extract area error when using both of the provided code samples you've provided.

This is the expected behaviour.

Both code samples take a 4032 wide x 3024 high landscape image as input, auto-orient it by rotating 90 degrees to create a 3024 wide x 4032 high portrait image, then correctly fail to extract an image with a width of 3583 pixels from an image of 3024 pixels wide.

@setrol
Copy link
Author

setrol commented Apr 22, 2024

oh, you are right, I was looking for the problem at the wrong point...
Just for context:
We are actually getting the extraction areas as percentages and need to do the area calculation ourselves. Therefore we first do a rotate(), then are fetching metadata() and do the calculation of the extract area regarding to the fetched metadata.
We did not take to account that the sharpStream.metadata() function still returns the original width and height with orientation set - we are trying to extract something that is not there..
Thank you for your input!

@setrol setrol closed this as completed Apr 22, 2024
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