diff --git a/etc/loris2.conf b/etc/loris2.conf index ca73aa97..688f9fab 100644 --- a/etc/loris2.conf +++ b/etc/loris2.conf @@ -116,6 +116,9 @@ target_formats = ['jpg','png','gif','webp'] [[png]] impl = 'PNG_Transformer' + [[gif]] + impl = 'GIF_Transformer' + [[jp2]] impl = 'KakaduJP2Transformer' tmp_dp = '/tmp/loris/tmp/jp2' # rwx diff --git a/loris/img_info.py b/loris/img_info.py index 9b74ec4d..03149df1 100644 --- a/loris/img_info.py +++ b/loris/img_info.py @@ -173,7 +173,7 @@ def from_image_file(self, formats=[], max_size_above_full=200): if self.src_format == 'jp2': self._from_jp2(self.src_img_fp) - elif self.src_format in ('jpg','tif','png'): + elif self.src_format in ('gif', 'jpg', 'tif', 'png'): self._extract_with_pillow(self.src_img_fp) else: raise ImageInfoException( diff --git a/loris/transforms.py b/loris/transforms.py index 700382e9..1b2ccd01 100644 --- a/loris/transforms.py +++ b/loris/transforms.py @@ -212,6 +212,8 @@ class TIF_Transformer(_PillowTransformer): class PNG_Transformer(_PillowTransformer): pass +class GIF_Transformer(_PillowTransformer): + pass class _AbstractJP2Transformer(_AbstractTransformer): ''' diff --git a/tests/img/three_static.gif b/tests/img/three_static.gif new file mode 100644 index 00000000..fe5ef1ca Binary files /dev/null and b/tests/img/three_static.gif differ diff --git a/tests/img_info_t.py b/tests/img_info_t.py index abef47ba..d94f4fff 100644 --- a/tests/img_info_t.py +++ b/tests/img_info_t.py @@ -207,6 +207,31 @@ def test_png_info_from_image(self): self.assertEqual(info.profile.description, profile[1]) self.assertEqual(info.sizes, self.test_png_sizes) + def test_gif_info_from_image(self): + fp = self.test_gif_static_fp + fmt = self.test_gif_static_fmt + + info = img_info.ImageInfo(self.app, src_img_fp=fp, src_format=fmt) + + profile = ["http://iiif.io/api/image/2/level2.json", { + "formats": [ "jpg", "png", "gif", "webp", "tif" ], + "qualities": [ "default", "gray", "bitonal" ], + "supports": [ + "canonicalLinkHeader", + "profileLinkHeader", + "mirroring", + "rotationArbitrary", + "regionSquare", + "sizeAboveFull" + ] + } + ] + + self.assertEqual(info.width, self.test_gif_static_dims[0]) + self.assertEqual(info.height, self.test_gif_static_dims[1]) + self.assertEqual(info.sizes, self.test_gif_static_sizes) + self.assertEqual(info.profile.compliance_uri, profile[0]) + self.assertEqual(info.profile.description, profile[1]) def test_tiff_info_from_image(self): fp = self.test_tiff_fp diff --git a/tests/loris_t.py b/tests/loris_t.py index 8c94cf0b..d999331b 100755 --- a/tests/loris_t.py +++ b/tests/loris_t.py @@ -96,6 +96,13 @@ def setUp(self): self.test_tiff_dims = (839,1080) self.test_tiff_sizes = [] + self.test_gif_static_fp = path.join(self.test_img_dir, 'three_static.gif') + self.test_gif_static_fmt = 'gif' + self.test_gif_static_id = 'three_static.gif' + self.test_gif_static_uri = '%s/%s' % (self.URI_BASE, self.test_gif_static_id) + self.test_gif_static_dims = (288, 250) # w,h + self.test_gif_static_sizes = [] + self.test_png_fp = path.join(self.test_img_dir,'henneken.png') self.test_png_fp2 = path.join(self.test_img_dir2,'henneken.png') self.test_png_fmt = 'png' diff --git a/tests/webapp_t.py b/tests/webapp_t.py index adc908d3..31d4d760 100644 --- a/tests/webapp_t.py +++ b/tests/webapp_t.py @@ -397,6 +397,15 @@ def test_bare_identifier_request_303_gets_info(self): info = img_info.ImageInfo.from_json_fp(tmp_fp) self.assertEqual(info.width, self.test_jp2_color_dims[0]) + def test_gif_identifier(self): + # Should be able to request source GIF in a supported target format + # Note: cannot use @pytest.mark.parametrize here because this is a unittest.TestCase subclass + for target_format in ( 'gif', 'jpg', 'png', 'webp'): + identifier = 'three_static.gif' + to_get = '/%s/full/full/0/default.%s' % (identifier, target_format) + resp = self.client.get(to_get) + self.assertEqual(resp.status_code, 200) + class InfoRequests(loris_t.LorisTest):