You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a palette, quantize an image using this palette and save it.
What did you expect to happen?
The palette information is stored correctly. I.e. the list of RGB values is the same in the saved image.
E.g. [0, 0, 0, 209, 254, 76, 217, 3, 3, 10, 66, 192,...]
What actually happened?
The list of RGB values is corrupted.
E.g. [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3,...]
What are your OS, Python and Pillow versions?
OS: Tested on Windows and Azure Databricks (Ubuntu)
Python: 3.6 & 3.8
Pillow: 8.3.1 has the issue
fromPILimportImagefromitertoolsimportcycleimportnumpyasnppalette= [0, 0, 0, 209, 254, 76, 217, 3, 3, 10, 66, 192]
# palette must contain 768 values (256 * 3)# repeat the colours until we get therecolor_iter=cycle(palette)
expanded_palette_format= []
whileTrue:
expanded_palette_format.append(next(color_iter))
iflen(expanded_palette_format) ==768:
breakassertlen(expanded_palette_format) ==768palette_image=Image.new('P', (16, 16))
palette_image.putpalette(expanded_palette_format)
# a new image that we want to apply the palette toim_to_palette=np.array(
[
[[0, 0, 0,],[209, 254, 76], [217, 3, 3], [10, 66, 192]],
[[0, 0, 0,],[209, 254, 76], [217, 3, 3], [10, 66, 192]],
[[0, 0, 0,],[209, 254, 76], [217, 3, 3], [10, 66, 192]],
[[0, 0, 0,],[209, 254, 76], [217, 3, 3], [10, 66, 192]]
],
np.uint8
)
im=Image.fromarray(im_to_palette).quantize(palette=palette_image, dither=0)
im.save(r"test.png")
saved_im=Image.open(r"test.png")
assertim.getpalette() ==saved_im.getpalette()
# AssertionError
Please note that if I specifically pass the 'GIF' argument on save, it has the expected behaviour.
What did you do?
Create a palette, quantize an image using this palette and save it.
What did you expect to happen?
The palette information is stored correctly. I.e. the list of RGB values is the same in the saved image.
E.g. [0, 0, 0, 209, 254, 76, 217, 3, 3, 10, 66, 192,...]
What actually happened?
The list of RGB values is corrupted.
E.g. [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3,...]
What are your OS, Python and Pillow versions?
Please note that if I specifically pass the 'GIF' argument on save, it has the expected behaviour.
The text was updated successfully, but these errors were encountered: