-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Prevent returning optimized image if it's larger than original #9214
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
Prevent returning optimized image if it's larger than original #9214
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense indeed 👍
| const optimized = await sharpInstance | ||
| .toBuffer({ resolveWithObject: true }) | ||
| .then(({ data, info }) => ({ | ||
| buffer: data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't you just do buffer.length < data.length here ? that would help us keep the simple return of promise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to edit the size param below too, but indeed it looks better that way.
Codecov Report
@@ Coverage Diff @@
## master #9214 +/- ##
==========================================
- Coverage 34.64% 34.64% -0.01%
==========================================
Files 1308 1308
Lines 14431 14446 +15
Branches 1432 1435 +3
==========================================
+ Hits 5000 5005 +5
- Misses 8517 8527 +10
Partials 914 914
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
BTW. Is normal that running |
Yep the legacy code haven't been prettified to avoid conflicts so we only run them on commit (so on changed files only) :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 💯 nice job
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: |
What does it do?
Prevent returning optimized image if it's larger than the original. It's mostly visible on PNG images, and it's a known behavior of
sharplovell/sharp#1110, lovell/sharp#1017, lovell/sharp#600, lovell/sharp#478.Why is it needed?
When the user is uploading an already optimized image, or just the optimizer is unable to reduce the size, we should keep the image that is smaller.
Related issue(s)/PR(s)
I didn't find any of them.