From 42e2bed4a6a35b140352eba13b2e695023ca66e4 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 2 Jan 2019 12:45:07 +1100 Subject: [PATCH] If SGI image is RGB mode, then apply image/rgb mimetype --- Tests/test_file_sgi.py | 3 +++ src/PIL/SgiImagePlugin.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_sgi.py b/Tests/test_file_sgi.py index aa33c9d93..76f8a3841 100644 --- a/Tests/test_file_sgi.py +++ b/Tests/test_file_sgi.py @@ -12,6 +12,7 @@ class TestFileSgi(PillowTestCase): im = Image.open(test_file) self.assert_image_equal(im, hopper()) + self.assertEqual(im.get_format_mimetype(), 'image/rgb') def test_rgb16(self): test_file = "Tests/images/hopper16.rgb" @@ -26,6 +27,7 @@ class TestFileSgi(PillowTestCase): im = Image.open(test_file) self.assert_image_similar(im, hopper('L'), 2) + self.assertEqual(im.get_format_mimetype(), 'image/sgi') def test_rgba(self): # Created with ImageMagick: @@ -35,6 +37,7 @@ class TestFileSgi(PillowTestCase): im = Image.open(test_file) target = Image.open('Tests/images/transparent.png') self.assert_image_equal(im, target) + self.assertEqual(im.get_format_mimetype(), 'image/sgi') def test_rle(self): # Created with ImageMagick: diff --git a/src/PIL/SgiImagePlugin.py b/src/PIL/SgiImagePlugin.py index 88df35135..91753380d 100644 --- a/src/PIL/SgiImagePlugin.py +++ b/src/PIL/SgiImagePlugin.py @@ -98,6 +98,8 @@ class SgiImageFile(ImageFile.ImageFile): self._size = xsize, ysize self.mode = rawmode.split(";")[0] + if self.mode == 'RGB': + self.custom_mimetype = 'image/rgb' # orientation -1 : scanlines begins at the bottom-left corner orientation = -1 @@ -220,7 +222,6 @@ Image.register_decoder("SGI16", SGI16Decoder) Image.register_open(SgiImageFile.format, SgiImageFile, _accept) Image.register_save(SgiImageFile.format, _save) Image.register_mime(SgiImageFile.format, "image/sgi") -Image.register_mime(SgiImageFile.format, "image/rgb") Image.register_extensions(SgiImageFile.format, [".bw", ".rgb", ".rgba", ".sgi"])