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

Consider default image when selecting mode for PNG save_all #7437

Merged
merged 2 commits into from
Oct 13, 2023

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Oct 2, 2023

Resolves #7459

Sequel to #6610

  1. While that PR theoretically considers all images, and "upgrades" images to more complex modes, it did not consider the default image.

    if default_image:
    chain = itertools.chain(append_images)
    else:
    chain = itertools.chain([im], append_images)
    for im_seq in chain:
    for im_frame in ImageSequence.Iterator(im_seq):
    modes.add(im_frame.mode)
    for mode in ("RGBA", "RGB", "P"):
    if mode in modes:
    break

    This means that when the default image is saved with the chosen mode, it may not be the ideal choice. This PR considers the mode of the default image, and converts the default image before saving if needed.

  2. Because that PR made it so that P images are "upgraded" to RGB if there are any RGB images present, a RGB to P conversion will no longer occur at

    for im_seq in chain:
    for im_frame in ImageSequence.Iterator(im_seq):
    if im_frame.mode == rawmode:
    im_frame = im_frame.copy()
    else:
    if rawmode == "P":
    im_frame = im_frame.convert(rawmode, palette=im.palette)
    else:
    im_frame = im_frame.convert(rawmode)

    meaning that the palette argument is unneeded.

    Pillow/src/PIL/Image.py

    Lines 907 to 909 in aaa7587

    :param palette: Palette to use when converting from mode "RGB"
    to "P". Available palettes are :data:`Palette.WEB` or
    :data:`Palette.ADAPTIVE`.

@hugovk hugovk merged commit 101154e into python-pillow:main Oct 13, 2023
50 checks passed
@radarhere radarhere deleted the apng branch October 13, 2023 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when saving apng with save_all
2 participants