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

Upload plugin: "sizeOptimization" parameter in the config of plugin doesn't correctly apply to thumbnails and breakpoints. #20163

Open
chupacabri opened this issue Apr 19, 2024 · 0 comments
Assignees
Labels
issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: core:upload Source is core/upload package status: pending reproduction Waiting for free time to reproduce the issue, or more information

Comments

@chupacabri
Copy link

chupacabri commented Apr 19, 2024

Bug report

Required System information

  • Node.js version: v18.20.2
  • NPM version: 10.5.0
  • Strapi version: 4.23.1
  • Database: sqlite
  • Is your project Javascript or Typescript: Javascript

Describe the bug

"sizeOptimization" parameter in the config of plugin doesn't correctly apply to thumbnails and breakpoints.

Expected behavior

"sizeOptimization" (in the config of plugin) parameter should affect only original image and for all other calls of sharp() we need to apply quality 100 if our source image is a new one after our optimizations.

at this moment the value of the sharp "quality" is always 80 for jpeg/webp/jp2/tiff (by default), 100 for png, 50 avif/heif for thumbnails and breakpoints.

so if you apply quality 80 by "sizeOptimization: true" for original image (jpeg) and after you apply quality 80 (by sharp defaults) for dependent images like thumbnails and breakpoints then the quality of the images will be little bit bad because you apply two optimizations (by 80) twice.

so if you will use "sizeOptimization: false" then your original image (jpeg) will be with quality 100, and dependents will be with quality 80.

I guess that will be good to apply optimization only to original image and for dependent images we need to set 100 quality in the sharp() calls.

Also I think we need to set up default settings of sharp for quality by different formats when we use "sizeOptimization".

Code snippets

releases/4.23.1:

There is optimization:

transformer[format]({ quality: sizeOptimization ? 80 : 100 });

Default quality 80 is applied:

await writeStreamToFile(file.getStream().pipe(sharp().resize(options)), filePath);

v5/main:

There is optimization:

transformer[format]({ quality: sizeOptimization ? 80 : 100 });

Default quality 80 is applied:

await writeStreamToFile(file.getStream().pipe(sharp().resize(options)), filePath);

@joshuaellis joshuaellis added issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: core:upload Source is core/upload package status: pending reproduction Waiting for free time to reproduce the issue, or more information labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: core:upload Source is core/upload package status: pending reproduction Waiting for free time to reproduce the issue, or more information
Projects
Status: To be reviewed
Status: To review
Development

No branches or pull requests

3 participants