Page MenuHomePhabricator

Images with embedded thumbnail whose orientation (rotation) is different than that of the main image render thumbnails wrong (smaller than they should be)
Closed, ResolvedPublic

Description

Images with embedded thumbnail whose orientation (rotation) is different than that of the main image render thumbnails wrong (smaller than they should be).

Originally reported at https://commons.wikimedia.org/wiki/Commons:Village_pump#Odd_stretched_thumbnails

Example affected file: File:Hellemani_torn_2011_(1).jpg (check the old version from 9 June 2012 for demonstration)

What I suspect happens is that we try to render e.g. a 337-pixel-wide thumbnail of the 1456×2592px original file, but at some point the dimensions are mixed up and we end up calculating the dimensions as if the file was 2592×1456px – so instead of a 337×600px thumbnail, we end up with a 337×189px thumbnail, and because aspect ratio is preserved, that in turn becomes 106×189px. This is probably a PHP or ImageMagick bug – I don't know where the issue is, but I can't reproduce it locally using PHP 7.1.5-1 and ImageMagick 6.8.9-9.

I was able to fix the original file by changing the thumbnail orientation to match the image:

… and to "break" the fixed file by changing the orientation not to match:

Revisions and Commits

rTHMBREXT Thumbor Plugins
Restricted Differential Revision

Event Timeline

May T173804 be a duplicate?

File https://commons.wikimedia.org/wiki/File:Stele_Marktstr._15_(Lenggries)_Weltkriegsopfer.jpg was fine until recent renaming, but shows now the same issue (update: meanwhile fixed by original uploader). Hence it must be a problem with the active preview creation.

Similar symptoms, but doesn't seem like a duplicate. The fix for T173804 worked for the files listed there, but not for this one.

Stock Mediawiki, OS X and Chrome all seem to agree that this image isn't rotated. But exiftool, which Thumbor relies on, seems to think it should be rotated:

MacBook-Pro-de-Gilles:Downloads gillesdubuc$ exiftool -orientation -imagesize tower.jpg 
Orientation                     : Rotate 90 CW
Image Size                      : 1456x2592

It seems like another case of being overzealous in interpreting that EXIF field, but with this time exiftool being the culprit rather than imagemagick.

exiv2 seems to fare better and find that the image isn't rotated. Unfortunately exiv2's support of ICC profile is new (latest version, 0.26) and only lets us extract the profile, not check its name first. It's going to be difficult to use it as a drop-in replacement for exiftool right now. Thumbor uses pyexiv2 (wrapper for exiv2), which means we might be able to at least read the orientation with pyexiv2, and keep doing the rest with exiftool for now, until exiv2 supports all the features we need.

Gilles added a revision: Restricted Differential Revision.Sep 26 2017, 10:41 AM
Gilles added a project: Patch-For-Review.

Change 380747 had a related patch set uploaded (by Gilles; owner: Gilles):
[operations/debs/python-thumbor-wikimedia@master] Upgrade to 1.6

https://gerrit.wikimedia.org/r/380747

Change 380747 merged by Filippo Giunchedi:
[operations/debs/python-thumbor-wikimedia@master] Upgrade to 1.6

https://gerrit.wikimedia.org/r/380747

Mentioned in SAL (#wikimedia-operations) [2017-10-02T09:12:14Z] <godog> roll-restart thumbor to upgrade to 1.6 - T172556

Purge affected files + clear your browser cache and the thumbnails should be fixed, including for old versions.