Currently the image size of a media thumbnail is saved once, only on the first creation. We should recalculate it on update, because if we change the thumbnail, for example with changing the order of a gallery, the size stays and the thumbnail is warped.

CommentFileSizeAuthor
#2 recalculate_thumbnail-2786881-2.patch581 byteschr.fritsch

Comments

chr.fritsch created an issue. See original summary.

chr.fritsch’s picture

Status: Active » Needs review
StatusFileSize
new581 bytes

Here is a first patch

slashrsm’s picture

Status: Needs review » Needs work
Issue tags: +D8Media
+++ b/src/Entity/Media.php
@@ -246,6 +246,10 @@ class Media extends ContentEntityBase implements MediaInterface {
+
+    $image = \Drupal::service('image.factory')->get($thumbnail_uri);
+    $this->thumbnail->width = $image->getWidth();
+    $this->thumbnail->height = $image->getHeight();

Image field does this automatically if w/h are empty. Should we rely on that instead?

chr.fritsch’s picture

We could. But i guess then we have to empty thumbnail w/h in automaticallySetThumbnail

anton-staroverov’s picture

Status: Needs work » Reviewed & tested by the community

@chr.fritsch is right. So let's set w/h explicitly?

Also marking RTBC -- working for us.

marcoscano’s picture

Status: Reviewed & tested by the community » Needs work

Moving back to NW because #3 was not addressed yet or agreed upon by the reviewer.