Skip to content
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

[Asset] Stream image thumbnail action improvements #624

Closed
markus-moser opened this issue Dec 9, 2024 · 4 comments · Fixed by #629 or #643
Closed

[Asset] Stream image thumbnail action improvements #624

markus-moser opened this issue Dec 9, 2024 · 4 comments · Fixed by #629 or #643

Comments

@markus-moser
Copy link

markus-moser commented Dec 9, 2024

This is a follow up to #614

I tested it with this call:

/pimcore-studio/api/assets/{ID}/image/stream/custom?mimeType=JPEG&resizeMode=scaleByWidth&height=200&width=100&contain=true

The pendant in the classic bundle would be:

/admin/asset/get-image-thumbnail?id={ID}&width=200&height=100&contain=true

  • I received a strange result for a portrait image.
    Studio:
    Image
    Classic Bundle:
    Image

  • Tested it also with an icon SVG:
    Studio:
    Image
    Classic Bundle:
    Image

  • Not sure if my calls are wrong and the URL format needs to be different but at the moment it's strange that I need to combine the resizeMode with contain, cover and frame to create the URL. Maybe contain, coverand frame need to get resize modes instead?

I tested with the following images:
Archiv.zip

@mcop1
Copy link
Contributor

mcop1 commented Dec 10, 2024

Quick update:

Strange at first glance, true, but the thing is, that the photo was taken with a smartphone (I assume) and it has an orientation flag:
Image
Image

The studio api endpoint uses the original format while the old classic bundle rotates the image. But, agreed, we should get the same results here, I will have a deeper look into it.

Note: Since this endpoint is based on the preview thumbnail endpoint, we probably have the same problem there.

@mcop1
Copy link
Contributor

mcop1 commented Dec 10, 2024

I think this isnt a problem with the endpoint, seems more like a general bug to me.

Reproducing the problem:

/pimcore-studio/api/assets/435/image/stream/custom?mimeType=JPEG&resizeMode=scaleByWidth&width=140

Why? Because in the endpoint we set preserveMetadata to true, when the file format equals jpeg:

if ($parameters->getMimeType() === MimeTypes::JPEG->value) {

But the core tries to detect the orientation of the image and adds a rotate transformation automatically. Therefore the image gets rotated to the orientation mentioned in the metadata AND the orientation metadata gets preserved, which results in extra rotation, when the image gets displayed.

Auto rotate transformation in the core: https://github.com/pimcore/pimcore/blob/3ffaeac8d9f07f877ea4f469015be1774de447b9/models/Asset/Image/Thumbnail/Processor.php#L301

But why do the old admin ui endpoints seemingly provide a correct result?

Somehow adding the quality parameter to the thumbnail config results in a loss of exif metadata- even if you set preserveMetadata to true.
And that is exactly what happens in the old admin ui endpoints. They all have the quality option explicitly set or use the legacy way to create thumbnail configs. The legacy way applies a default of 85 to the quality parameter:
https://github.com/pimcore/pimcore/blob/3ffaeac8d9f07f877ea4f469015be1774de447b9/models/Asset/Image/Thumbnail/Config.php#L501

How to get a correct result with studio endpoint?

Just add the quality parameter like this
/pimcore-studio/api/assets/435/image/stream/custom?mimeType=JPEG&resizeMode=scaleByWidth&width=140&quality=85
But again, this will result in loosing exif metadata.

How to reproduce this issue in the ui directly?

Image

Use the Download thumbnail functionality in the sidebar. Try to download a thumbnail with and without quality parameter set.

Quick fixes

  1. Add a default value to quality parameter in the studio endpoint.
  2. Prevent the core from automatically adding a rotate transformation if quality isnt set.
  3. Never preserve metadata in thumbnail endpoints

IMO

In my opinion there are at least 2 bugs, we would need to investigate:

  1. Why do we lose exif metadata if quality parameter is set and preserveMetadata is set? Guess exif metadata isnt that important for thumbnails, but do we use the same library/implementation for other transformations as well?
  2. Why do we automatically rotate the image, if metadata should be preserved? Maybe this was implemented as a workaround to 1.)?

@markus-moser
Copy link
Author

test.svg.zip

@mcop1
Copy link
Contributor

mcop1 commented Dec 16, 2024

I adopted the behavior, but it still feels strange, e.g.

http://localhost/pimcore-studio/api/assets/438/image/stream/custom?width=1001&resizeMode=resize&height=100&mimeType=JPEG

wont resize the image, but

http://localhost/pimcore-studio/api/assets/438/image/stream/custom?width=1001&resizeMode=resize&height=100&mimeType=PNG

will.

Same behavior can be observed with admin-ui-classic endpoints:

http://localhost/admin/asset/get-image-thumbnail?id=438&width=200&height=100

does resize the image, but

http://localhost/admin/asset/get-image-thumbnail?id=438&width=200&height=100&format=JPEG

doesn´t. Note: Admin ui classic uses PNG as default.

In generel I got better results with PNGs. Maybe we should add a default value to PNG here?

At least the new endpoint should now work like the admin ui endpoint with SVG and orientation. ResizeMode should be fully optional now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants