aws-solutions / serverless-image-handler

A solution to dynamically handle images on the fly, utilizing SharpJS
Apache License 2.0
1.31k stars 528 forks source link

Options for automatic rotation of the images based on EXIF info #572

Closed albanx closed 11 hours ago

albanx commented 1 week ago

One issue I have is that customers upload photos from the smartphones, which are rotated, and the rotation is written in the EXIF info. The problem is that the resize/ or the AUTO_WEBP option clears exif and it shows the images rotated by 90 degree for example.

Reading SHARP documentation looks like if the

sharp(imageBuffer)
  .rotate() // Automatically rotate based on EXIF orientation

is called, the rotation is done automatically and solves the issue.

Is it possible to add this feature as configuration Variable?

simonkrol commented 1 week ago

Hi @albanx, If you include the strip_exif filter on your image requests, do the images come out formatted properly? Simon

albanx commented 1 week ago

@simonkrol yes they do, actually that is the solution I am going to adopt as now. I was looking for some pre-setting in the setup as feature , so that this will avoid making the URL longer.

Thank you though, this is a great solution, love it

simonkrol commented 1 week ago

Hi @albanx, If you'd like to try and avoid making the URL longer, If you aren't already using the REWRITE_MATCH_PATTERN and REWRITE_SUBSTITUTION template parameters, you can modify them to match any request, and include the strip_exif filter. Something like

REWRITE_MATCH_PATTERN=/(^.*$)/gm
REWRITE_SUBSTITUTION=/filters:strip_exif()/$1

might do the trick.

That will cause every request sent to your distribution to automatically prepend the request with /filters:strip_exif(). Keep in mind this could cause issues if you ever use base64 encoded requests.

Let me know how it goes, Simon

albanx commented 1 week ago

Ok that looks nice, I didn't know these options. Thank you.

So far I have only used thumbor /fit-in/. I have not used the other options like base64 ones.

simonkrol commented 11 hours ago

Hi @albanx, I'm going to close this issue for now, if you have any other questions or concerns, please feel free to reopen this issue or create a new issue.

Thanks for your interest in SIH, Simon