unjs / ipx

🖼️ High performance, secure and easy-to-use image optimizer.
MIT License
1.54k stars 61 forks source link

Support auto-rotation based on EXIF data #81

Open ascorbic opened 2 years ago

ascorbic commented 2 years ago

If sharp's rotate() function is called without arguments then it will try to automatically rotate the image based on exif data. ipx currently doesn't support this, and can only do explicit rotation. It would be good if it either allowed rotate to be called without an angle, or if auto-rotation was the default (which would be my suggestion)

pi0 commented 2 years ago

Seems a good idea. Sharp has a global useExifOrientation option. We had it in previous versions of IPX (See #13) which can add back support and possibly enable by default. However not sure what was reasons sharp kept it disabled by default.

ascorbic commented 2 years ago

The global option does seem like a good idea

tmlmt commented 1 year ago

Hi both, I started using ipx / nuxt-image and have just stumbled upon this issue for images in portrait format that I've been using. Indeed, it seems that the useExifOrientation option (introduced 6 years ago in this commit of sharp) was set to false from the beginning. See commit text.

Any idea when this could be implemented in ipx?

tmlmt commented 11 months ago

Turns out it works just by providing the useExifOrientation option to sharp.

For instance in my case in Nuxt with the image module, in nuxt.config.ts:

  image: {
    sharp: {
      useExifOrientation: true,
    },
  },

or for IPX only, with the Programatic API:

const ipx = createIPX({
    // ...
    sharpOptions: {
        useExifOrientation: true,
    }
});
michaelmannucci commented 10 months ago

Turns out it works just by providing the useExifOrientation option to sharp.

For instance in my case in Nuxt with the image module, in nuxt.config.ts:

  image: {
    sharp: {
      useExifOrientation: true,
    },
  },

or for IPX only, with the Programatic API:

const ipx = createIPX({
    // ...
    sharpOptions: {
        useExifOrientation: true,
    }
});

THat didn't seem to work for me. I'm using NextJS, does it make a difference?