-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fix image scaling to return the originals when no scaling is required #92
Conversation
This comment has been minimized.
This comment has been minimized.
@jenkins-plone-org please run jobs |
@jenkins-plone-org please run jobs |
This is jot only a plone.restapi use-case but a general one, when one wants to create a full cacheable URL of the original image instead of using the @@images/image like url. |
@jenkins-plone-org please run jobs |
It seems this breaks plone.restapi tests, which do actually test that the REST API original download url is not the original, but a scale 🤔 |
…e directly saved as image value
0ae1e2f
to
5a4a41d
Compare
@jenkins-plone-org please run jobs |
1 similar comment
@jenkins-plone-org please run jobs |
@erral would you mind having a look at this failing test? I suspect this if/else stmt is causing this: |
Will do. |
This PR needs a slight change in plone.restapi too. The point is that now the original image URL is not a "scale" but the original image, so it is not converted to PNG or JPEG depending on Plone version. With the previous code we will have always a recreated scale so the URL of the item was also changed. Now, in the linked code lines, we need to distinguish between the original URL which will be ending in gif because the tested image is a gif, and the scale URLs which will be PNG or JPEG. |
With this change the original image is used with all its metadata and with the original compression, which could easily be twice the size of a scaled representation of the same dimensions. Is that really intended? |
@bastei Shouldn't original be original? Also I assume that current implementation might convert optimized JPEG2000 into older JPEG version, probably increasing the size even dimensions stay and compression is added. 🤔 If it is really intended that the "original" means compressed version of the original just with matching dimensions. Then this pull could be dismissed. |
@erral thanks for the clarification. I actually kind of got that point. Though, I don't fully understand the test and how it works for the different configurations. I usually try really hard to keep those if/else statements out of tests because of this. When reading the test I have to first check what GIF_SCALE_FORMAT is. Then I have to find the if/else and this is where Iost track. Why did that change in Plone 5.1? So my recommendation would be that we try to refactor the plone.restapi test to work without those indirections and the if/else statements if that's possible. Since you wrote the test code if I am not mistaken I was hoping you could help us with that. :) |
@datakurre Well, I'm not sure if I have an overview of all the use cases here, but isn't it that the original image would be submitted only because a scale of the same dimensions (possibly by accident) is requested? So not the original image is requested, but only a (web-optimized) image representation with the dimensions of the original image. As to JPEG2000: There is nearly no support in browsers for that compression, so not converting it would be a real problem. I think providing modern compressions is out of scope here. It involves providing the same scale in different compression formats, but again: Not necessarily the one of the original. In my opinion, providing an ideal web-optimized representation of an image should be the responsibility of Plone, not the editor. |
@tisto Yes, it's not easy to follow. At some point in Plone 5.1 the images scales started being created as PNG images instead of JPEG as previously. According to plone.scale's changelog this was changed in plone.scale 2.0. Vanilla Plone 5 uses plone.scale 1.4.2 and Vanilla Plone 5.1 uses plone.scale 3.0. So what this test tries to do is to compare the URLs of the generated scales. We are using a GIF image as a test image in plone.restapi. As the URLs differ depending on the Plone version (ones are whatever.jpg and other whatever.png), I needed that GIF_SCALE_FORMAT to identify the extension. I could write the test in some other way, for instance instead of checking the full URL, check that it contains the UUID of the generated scale, or something like that. Anyway we need a new branch in plone.restapi so we can test it against the changes of this PR. I can work on it, no problem. |
@bastei @erral @tisto About this pull removing a feature of "compressed scale with original dimensions". Well, my understanding is that the current "compressed original" image scale was unintentional side-effect of generating unique URL for the original (for caching). So, the original scale was supposed to be the original image, not compressed scale. (This is also how the "original" size has traditionally worked in Plone.) But if also "compressed image with original dimensions" is now a use case, that is new to Plone and should be implemented as a new dynamically calculated scale for plone.scale, maybe. So that also in plone.restapi represetation https://plonerestapi.readthedocs.io/en/latest/plone-content.html#image it would be a "scale" not "download". "download" IMO should be the original, not compressed one. |
@datakurre I think our original assumptions are correct, and the ones who implemented that confirmed it. It's a side effect. It should be the original, otherwise you don't have a way using shorthands to get it. I would stick to the original plan. |
Yes, I understand the same. |
@datakurre couldn't agree more. We introduced a bug in plone.restapi and now we are fixing that. Easy as this. :) |
@datakurre Sorry, maybe I was unclear. "Download" should be the original image, of course! What I meant was actually a "scale". If I load a scale that has by chance the same dimensions as the original image, I don't get a scale (in terms of compressed image) anymore, but the original image. Or am I wrong? |
@bastei Thanks for correcting! That's been taken account with And that's been also tested in https://github.com/plone/plone.namedfile/pull/92/files#diff-c69449fd7e2eea6ccbfd529cae4b114dR98 |
I have fixed the tests on plone.restapi side ti adapt to these changes. |
@datakurre Thanks for the explanation. The distinction between "download" and "scale" is not really straightforward from my point of view, but I understand the intention. |
@jenkins-plone-org please run jobs |
Ok. I guess I have to set up buildout coredev locally with p.restapi and p.namedfile checkout and then merge both PRs together...will look into it... |
I recall that Jenkins UI allows to pass list of PRs for tests. |
Yes, that's what I did, and Jenkins manages to inform both PRs that the tests are green or they failed. |
@erral do you have a link to that Jenkins job? |
@jensens do you want to have a look at this PR as well before we merge? |
Jenkins is green and we have three approvals. Will merge now. Then we can test it in the p.restapi PR... |
Plone REST API use cases require cacheable unique URL also for the original version of the image 1).
Until now, this has caused some performance penalty, created unnecessary blob and actually delivered lower quality copy of the original. Now, if the scaling parameters would result to exact size with the original, with now other parameters (e.g. change in format), no scaling will happen, but the scale URL will return the original blob.