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

Better image optimization #755

Open
aciccarello opened this issue Jul 18, 2024 · 1 comment
Open

Better image optimization #755

aciccarello opened this issue Jul 18, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@aciccarello
Copy link

Is your feature request related to a problem?

When testing out the media endpoint added in #700, I noticed that images I'd already processed through https://squoosh.app/ (e.g. this photo) were getting saved with a larger file size than the original. It's probably due to some extra optimization that aren't on by default in Sharp, but it seems like an opportunity for improvement.

Describe the solution you’d like

  1. A file size check before accepting a processed image over the original
  2. Additional options for JPEG encoding (or a more complex configuration option like Media endpoint: Support modifying images prior to uploading #394)

The downside of the file size check is that it could potentially lead to EXIF data unexpectedly not being removed and exposing location data. The Sharp JPEG encoding options could be exposed, though I'm not sure if always using that option would cause Sharp to always output jpeg format (even for PNGs).

Describe alternatives you’ve considered

I'm using a fork of the media endpoint code with some modifications to fix the issues I noticed. I have some logic about jpeg quality that probably is unique to my site, but otherwise the code could be a reference point for implementation.

https://github.com/aciccarello/ciccarello-indiekit/blob/3381efe087a99b4ceaed44af2bf8f80ca79e52a8/lib/endpoint-media/lib/media-transform.js#L14-L31

Additional context

On my site, images usually are shown with a max with of 1024, so I will often upload a 2048px wide image with lower jpeg quality for high DPI screens.

@aciccarello aciccarello added the enhancement New feature or request label Jul 18, 2024
@wingywing
Copy link

+1! Having issues ATM with .heic photos uploading from my Android phone. Would love if there's a setting to downsize images + convert to .PNG's.

source: bad seek to 4693056 heif: Error while loading plugin: No decoding plugin installed for this compression format (11.6003)

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

No branches or pull requests

2 participants