Skip to content

Limit image scales to those smaller than the original#1992

Open
davisagli wants to merge 3 commits into
mainfrom
image-scales-not-larger-than-original
Open

Limit image scales to those smaller than the original#1992
davisagli wants to merge 3 commits into
mainfrom
image-scales-not-larger-than-original

Conversation

@davisagli
Copy link
Copy Markdown
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
Copy Markdown

@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
Copy Markdown
Member Author

@jenkins-plone-org please run jobs

@davisagli davisagli requested a review from pnicolli February 27, 2026 01:33
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

jensens commented Mar 12, 2026

The code its simple enough and no burden.

@davisagli
Copy link
Copy Markdown
Member Author

I'm not sure what to do with this one.

My original goal was to avoid advertising unnecessary scales, which scrapers end up fetching (which then creates them and bloats the db).

But I think there are legitimate questions about how to tell when they are unnecessary. There's the case Jens brought up with SVGs that have a height and width embedded in the markup. (I think that's kind of dumb and counteracts one of the main benefits of a scalable vector format, but that's a bigger topic than we can tackle in this PR.) It's also possible to have scales that are not only scaling up or down but cropping to a different aspect ratio.

@jensens
Copy link
Copy Markdown
Member

jensens commented Mar 20, 2026

Tons of image scales polluting the ZODB is a topic broader than limiting the scales.

@pnicolli
Copy link
Copy Markdown
Contributor

My original goal was to avoid advertising unnecessary scales, which scrapers end up fetching (which then creates them and bloats the db).

I still think your goal is valid.

But I think there are legitimate questions about how to tell when they are unnecessary. There's the case Jens brought up with SVGs that have a height and width embedded in the markup. (I think that's kind of dumb and counteracts one of the main benefits of a scalable vector format, but that's a bigger topic than we can tackle in this PR.) It's also possible to have scales that are not only scaling up or down but cropping to a different aspect ratio.

Yes, the questions are legitimate, and I also think the svg topic is a bigger and important one. I see a potential loss of value if a bigger topic blocks a small but interesting improvement like this one, so can we have svgs work like they used to and push for this improvement for other raster images?

@jensens
Copy link
Copy Markdown
Member

jensens commented Mar 20, 2026

Yes, the questions are legitimate, and I also think the svg topic is a bigger and important one. I see a potential loss of value if a bigger topic blocks a small but interesting improvement like this one, so can we have svgs work like they used to and push for this improvement for other raster images?

Quite OT here, what about opening an new topic for discussion?

@jensens
Copy link
Copy Markdown
Member

jensens commented Mar 20, 2026

There's the case Jens brought up with SVGs that have a height and width embedded in the markup.

Just skip if its a SVG, done.

It's also possible to have scales that are not only scaling up or down but cropping to a different aspect ratio.

How does the code here modify the output of images crops?

@jensens jensens closed this Mar 20, 2026
@github-project-automation github-project-automation Bot moved this from In progress to Done in Bucharest Sprint 2026 Mar 20, 2026
@jensens jensens reopened this Mar 20, 2026
@jensens
Copy link
Copy Markdown
Member

jensens commented Mar 20, 2026

Sorry, accidentally closed, reopened.

@plone plone deleted a comment from mister-roboto Mar 20, 2026
@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 plone.restapi | 🛠️ Build #31893528 | 📁 Comparing 479f29b against latest (abebc6b)


🔍 Preview build

Show files changed (1 files in total): 📝 1 modified | ➕ 0 added | ➖ 0 deleted
File Status
endpoints/content-types.html 📝 modified

@pnicolli pnicolli moved this from Done to In progress in Bucharest Sprint 2026 Mar 24, 2026
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