Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submitting GIF support changes #428

Open
wants to merge 10 commits into
base: development
Choose a base branch
from
3 changes: 3 additions & 0 deletions etc/loris2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion loris/img_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions loris/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ class TIF_Transformer(_PillowTransformer):
class PNG_Transformer(_PillowTransformer):
pass

class GIF_Transformer(_PillowTransformer):
pass

class _AbstractJP2Transformer(_AbstractTransformer):
'''
Expand Down
Binary file added tests/img/three_static.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions tests/img_info_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/loris_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 9 additions & 0 deletions tests/webapp_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down