Skip to content

Limit image scales to those smaller than the original#1992

Open
davisagli wants to merge 2 commits intomainfrom
image-scales-not-larger-than-original
Open

Limit image scales to those smaller than the original#1992
davisagli wants to merge 2 commits intomainfrom
image-scales-not-larger-than-original

Conversation

@davisagli
Copy link
Member

@davisagli davisagli commented Feb 27, 2026

This makes the serialization of scales for image fields more consistent with the set of scales that comes from image_scales in catalog results. And it avoids storing duplicate data for large scales.

Related to plone/volto#7655


📚 Documentation preview 📚: https://plonerestapi--1992.org.readthedocs.build/

@davisagli davisagli requested a review from sneridagh February 27, 2026 01:29
@mister-roboto
Copy link

@davisagli thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@davisagli
Copy link
Member Author

@jenkins-plone-org please run jobs

@davisagli davisagli requested a review from pnicolli February 27, 2026 01:33
Copy link
Member

@sneridagh sneridagh left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@jensens jensens left a comment

Choose a reason for hiding this comment

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

You need an exception for SVG images.

@davisagli
Copy link
Member Author

@jensens Why an exception for SVG images?

@pnicolli pnicolli moved this from Todo to In progress in Bucharest Sprint 2026 Mar 10, 2026
Copy link
Member

@mauritsvanrees mauritsvanrees left a comment

Choose a reason for hiding this comment

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

Makes sense.

I suppose for SVG a larger scale does not bloat the database, as we scale this by editing the XML contents. Use here in plone.namedfile after checking the content type. So this could work:

if actual_width > width and getattr(field, "contentType", "") != "image/svg+xml"

@jensens
Copy link
Member

jensens commented Mar 12, 2026

Why an exception for SVG images?

a) SVG naturally scales up - its vector.
b) it does not blow up in size

@pnicolli
Copy link
Contributor

Correct, it's vector graphics and does not need scales at all
I mean, if the "scaling" is something that changes the default attributes, sure, but it would look overengineered to me

@jensens
Copy link
Member

jensens commented Mar 12, 2026

Correct, it's vector graphics and does not need scales at all

Misconception, if you dont apply a size to display it the SVG will show somehow (if not constrained by CSS, what you never know). So setting the size for display as we do already is good, but sufficient, we dont need to change anything, just keep as is.

@pnicolli
Copy link
Contributor

I disagree that we should not assume we have a theme on our sites, which is what I understand from your comment. If the theme does not constrain images properly, I don't think it's an issue at the lower level.

That being said, I did not mean that a proper svg image should not have it's own set of dimensions, I'm saying you don't need to generate more scales just to set different dimensions on it, imho. I would rather not have this kind of code to maintain if it was mine.

@jensens
Copy link
Member

jensens commented Mar 12, 2026

The code its simple enough and no burden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

6 participants