Skip to content

Only resize an image if it results in a smaller image size - #32787

Closed
jcjveraa wants to merge 3 commits into
nextcloud:masterfrom
jcjveraa:issue-32779-fix-2
Closed

Only resize an image if it results in a smaller image size#32787
jcjveraa wants to merge 3 commits into
nextcloud:masterfrom
jcjveraa:issue-32779-fix-2

Conversation

@jcjveraa

Copy link
Copy Markdown

Made to fixissue 32779.

Current default behaviour (for the last 2 years at least, or more) has been that any background file that is 'not an SVG or a GIF'
will be resized and stored as a PNG. When uploading a large compressed (e.g. webp or jpg) image this default results in (relatively) huge (1 MB+) background images, as per the issue I raised, as it then recompresses this e.g. 151kb jpg file to a 1MB png file. This is counterproductive as (per the original comments in the code) the intent of this function is to reduce file size.

With this change, only if the resulting image has a smaller file size than the original file, the new file is used.

Signed-off-by: JelleV 3942301+jcjveraa@users.noreply.github.com

Current default behaviour (for the last 2 years at least, or more) has been that any background file that is 'not an SVG or a GIF' will be resized *and stored as a PNG*. When uploading a large compressed (e.g. webp or jpg) image this default results in huge (1 MB+) background images. This is counterproductive as the intent of this function is to reduce file size.
With this change, only if the resulting image has a smaller
file size than the original file, the new file is used.
Signed-off-by: JelleV <3942301+jcjveraa@users.noreply.github.com>
Docstring was copy-pasted and not updated.
Signed-off-by: JelleV <3942301+jcjveraa@users.noreply.github.com>
@szaimenszaimen added bug 3. to review Waiting for reviews labels Jun 9, 2022
@szaimenszaimen added this to the Nextcloud 25 milestone Jun 9, 2022

@github-advanced-securitygithub-advanced-securityAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 12 potential problems in the proposed changes. Check the Files changed tab for more details.

@github-advanced-securitygithub-advanced-securityAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 12 potential problems in the proposed changes. Check the Files changed tab for more details.

Realized after having a think about my previous commits that the intent
of the original function was also to ensure images are stored in a
progressively loading format. With these further changes, I think the
original intern is captured more closely.
Signed-off-by: JelleV <3942301+jcjveraa@users.noreply.github.com>

@github-advanced-securitygithub-advanced-securityAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 14 potential problems in the proposed changes. Check the Files changed tab for more details.

@PVince81
PVince81 requested a review from CarlSchwanJune 10, 2022 13:09
This was referenced Aug 12, 2022
This was referenced Aug 24, 2022
This was referenced Sep 6, 2022
@skjnldsvskjnldsv mentioned this pull request Sep 15, 2022
This was referenced Sep 20, 2022
@blizzzblizzz modified the milestones: Nextcloud 25, Nextcloud 26Sep 22, 2022
@mrAceT

Copy link
Copy Markdown

Is it OK, that I suggest here that switching to WEBP for all previews might be the best way to go?
(besides the check that the new file should be smaler than the original.. that is always smart..)

PS: WEBP has been around for many years now and is perfect for the purpose we're talking about here..

@blizzzblizzz mentioned this pull request Feb 1, 2023
@skjnldsvskjnldsv mentioned this pull request Feb 23, 2023
@skjnldsv

Copy link
Copy Markdown
Member

Hey @jcjveraa thank you for this PR.
Sorry it takes such a long time!

Could you address all the psalm issues first?

@skjnldsvskjnldsv added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Mar 1, 2023
@skjnldsv

Copy link
Copy Markdown
Member

Superseded by #36471

@skjnldsvskjnldsv closed this Mar 1, 2023
@jcjveraa

jcjveraa commented Mar 1, 2023 via email

Copy link
Copy Markdown
Author

@skjnldsv

Copy link
Copy Markdown
Member

@jcjveraa the other one was pretty close/inspired from this one. But it also had tests, so huge bonus ;)
Thank you for pushing this over the last months, really helped moving forward!

@skjnldsvskjnldsv removed this from the Nextcloud 27 milestone Mar 2, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developingWork in progressbug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Custom login page background image size increases x7

6 participants

@jcjveraa@mrAceT@skjnldsv@github-advanced-security@blizzz@szaimen