Skip to content

Commit c46636d

Browse files
committed
Fixes broken test_orientation test for ImageMagick backend
So, from what I can tell, the test is failing on ImageMagick 6.9.12.98 (Ubuntu 24.04), but passing on ImageMagick 7. The root cause appears to be that ImageMagick 6 has a bug where `-colorspace RGB` corrupts grayscale pixel values during conversion. In our test, grayscale value 85 becomes 23 when `-colorspace RGB` is applied, even though the colorspace isn't actually changed (still reports as Gray). Testing showed: - `convert input.jpg -auto-orient -scale 30x30!` -> pixel value 85 - `convert input.jpg -auto-orient -colorspace RGB -scale 30x30!` -> pixel value 23 - `convert input.jpg -auto-orient -colorspace sRGB -scale 30x30!` -> pixel value 85 According to [ImageMagick's porting guide](https://imagemagick.org/script/porting.php), IM6 "does not have a true grayscale colorspace, and only fakes it with linear RGB colorspace", which likely explains this behavior. Since the test is about orientation handling, not colorspace conversion, the fix appears to be (for ImageMagick) specifically: pass `colorspace='sRGB'` instead in this specific test, which works correctly on both IM6 and IM7. However, that might break tests for other backends. The alternative is to change the `THUMBNAIL_COLORSPACE` setting for the ImageMagick tests only and fix the resulting breakages from cache key changes. I couldn't find an existing bug report for this to reference. I'm guessing the answer is the same-ish for #781. I can provide a `Dockerfile` to reproduce the behavior (even on a Mac OS host) if you'd like.
1 parent 7786fc9 commit c46636d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tests/thumbnail_tests/test_templatetags.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ def epsilon(x, y):
100100
)
101101

102102
for name in data_images:
103-
th = self.BACKEND.get_thumbnail('data/%s' % name, '30x30')
103+
# Use sRGB instead of RGB to avoid ImageMagick 6.9.12.x bug where -colorspace RGB
104+
# (the test default is RGB) corrupts grayscale pixel values
105+
th = self.BACKEND.get_thumbnail('data/%s' % name, '30x30', colorspace='sRGB')
104106
im = engine.get_image(th)
105107

106108
self.assertLess(epsilon(top, im.getpixel((14, 7))), 10)

0 commit comments

Comments
 (0)