Skip to content

autoOrient does not work well with avif if resized #4431

Closed

Description

@JSteunou

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.

0.34.3

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.14 Ubuntu 25.04 25.04 (Plucky Puffin)
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
    Memory: 13.00 GB / 30.43 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
    Yarn: 3.6.1 - ~/.nvm/versions/node/v22.14.0/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm

Does this problem relate to file caching?

The default behaviour of libvips is to cache input files, which can lead to EBUSY or EPERM errors on Windows.
Use sharp.cache(false) to switch this feature off.

  • Adding sharp.cache(false) does not fix this problem.

Does this problem relate to images appearing to have been rotated by 90 degrees?

Images that contain EXIF Orientation metadata are not auto-oriented. By default, EXIF metadata is removed.

  • To auto-orient pixel values use the parameter-less rotate() operation.

  • To retain EXIF Orientation use keepExif().

  • Using rotate() or keepExif() does not fix this problem.

What are the steps to reproduce?

Try to convert a portrait image to avif while resizing it

  1. load a portrait image with readFile for example
  2. transform into avif and auto rotate Sharp(input).resize({width: 600}).rotate().toFormat('avif').toBuffer()
  3. write it down width writeFile for example

Produced image is 90° rotated

What is the expected behaviour?

Image should not be rotated

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

  • try the above steps
  • note that rotate before resize do not produce the issue (or solve it depending how you see it)
  • note that this is specific to avif the issue is not present with webp or other format I tested

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

I hope you're not allergic to cheese :)

Image

Activity

  1. lovell commented on Jul 17, 2025

    @lovell
    Owner

    J'adore le fromage, c'est delicieux!

    Thanks for reporting, I can reproduce locally and think I know what the problem is.

  2. added this to the v0.34.4 milestone on Jul 19, 2025
  3. lovell commented on Jul 19, 2025

    @lovell
    Owner

    This problem was caused by orientation metadata being re-added during JPEG shrink-on-load. Commit 6284545 fixes this by moving the metadata removal to occur later, plus adds a test that would previously have failed to help prevent regression.

  4. adityapatadia commented on Aug 5, 2025

    @adityapatadia

    Not being pushy but this is a production bug for us. Any timeline for the 0.34.4 release?

  5. adityapatadia commented on Sep 12, 2025

    @adityapatadia

    This bug is causing production issue so if possible, please publish 0.34.4.

  6. lovell commented on Sep 15, 2025

    @lovell
    Owner

    A release candidate is now available with the fix if you're able to test:

    npm install [email protected]
    
  7. lovell commented on Sep 17, 2025

    @lovell
    Owner

    v0.34.4 now available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions