Skip to content

Commit

Permalink
feat(engines/pil.read_multiple): Use Pillow to save multipage images …
Browse files Browse the repository at this point in the history
…as GIF

The functionality provided by the images2gif module is part of Pillow
since 2015 [1]. It also renders `gifsicle` unnecessary in this context.

  1. https://pillow.readthedocs.io/en/stable/releasenotes/3.0.0.html
  • Loading branch information
scorphus committed Jan 23, 2024
1 parent f700492 commit 378ab80
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 663 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ sample_images:
convert tests/fixtures/images/10_years_of_Wikipedia_by_Guillaume_Paumier.jpg -orient LeftBottom tests/fixtures/images/10_years_of_Wikipedia_by_Guillaume_Paumier.jpg
curl -s https://upload.wikimedia.org/wikipedia/commons/6/6d/Christophe_Henner_-_June_2016.jpg -o tests/fixtures/images/Christophe_Henner_-_June_2016.jpg
curl -s https://upload.wikimedia.org/wikipedia/commons/3/31/Giunchedi%2C_Filippo_January_2015_01.jpg -o tests/fixtures/images/Giunchedi%2C_Filippo_January_2015_01.jpg
curl -s https://upload.wikimedia.org/wikipedia/commons/2/2c/Rotating_earth_%28large%29.gif -o tests/fixtures/images/Rotating_earth_\(large\).gif
convert tests/fixtures/images/Giunchedi%2C_Filippo_January_2015_01.jpg -colorspace CMYK tests/fixtures/images/Giunchedi%2C_Filippo_January_2015_01-cmyk.jpg
convert tests/fixtures/images/Giunchedi%2C_Filippo_January_2015_01.jpg tests/fixtures/images/Giunchedi%2C_Filippo_January_2015_01.png
convert tests/fixtures/images/Giunchedi%2C_Filippo_January_2015_01.jpg -colorspace gray tests/fixtures/images/Giunchedi%2C_Filippo_January_2015_01-grayscale.jpg
Expand Down
27 changes: 27 additions & 0 deletions tests/engines/test_pil.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,33 @@ def test_load_tif_16bit_per_channel_lsb(self):
expect(image_file.format).to_equal("PNG")
expect(image_file.size).to_equal((100, 100))

def test_load_animated_gif(self):
engine = Engine(self.context)
with open(join(STORAGE_PATH, "animated.gif"), "rb") as image_file:
buffer = image_file.read()
expect(buffer).not_to_equal(None)
engine.load(buffer, None)

final_bytes = BytesIO(engine.read())
image_file = Image.open(final_bytes)
expect(image_file.format).to_equal("GIF")
expect(image_file.size).to_equal((100, 100))
expect(image_file.is_animated).to_be_true()

def test_load_rotating_earth_gif(self):
engine = Engine(self.context)
with open(
join(STORAGE_PATH, "Rotating_earth_(large).gif"), "rb"
) as image_file:
buffer = image_file.read()
expect(buffer).not_to_equal(None)
engine.load(buffer, None)

final_bytes = BytesIO(engine.read())
image_file = Image.open(final_bytes)
expect(image_file.format).to_equal("GIF")
expect(image_file.size).to_equal((400, 400))

def test_load_tif_16bit_per_channel_msb(self):
engine = Engine(self.context)
with open(
Expand Down
4 changes: 3 additions & 1 deletion tests/fixtures/images/README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ They should ideally all be regenerated (or, should they not be possible to creat

[Commons-logo.svg](https://en.wikipedia.org/wiki/File:Commons-logo.svg) - Wikimedia Foundation - [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/deed.en)

[10_years_of_Wikipedia_by_Guillaume_Paumier.jpg](https://commons.wikimedia.org/wiki/File:10_years_of_Wikipedia_by_Guillaume_Paumier.jpg) - Pierre-Selim Huard - [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/deed.en)
[10_years_of_Wikipedia_by_Guillaume_Paumier.jpg](https://commons.wikimedia.org/wiki/File:10_years_of_Wikipedia_by_Guillaume_Paumier.jpg) - Pierre-Selim Huard - [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/deed.en)

[Rotating_earth_(large).gif](https://commons.wikimedia.org/wiki/File:Rotating_earth_(large).gif) - Marvel - [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/deed.en)
Binary file added tests/fixtures/images/Rotating_earth_(large).gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 378ab80

Please sign in to comment.