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

Remove fully opaque transparent channels #67

Open
BertrandBordage opened this issue Jun 27, 2018 · 3 comments
Open

Remove fully opaque transparent channels #67

BertrandBordage opened this issue Jun 27, 2018 · 3 comments

Comments

@BertrandBordage
Copy link
Member

As discussed in #66, it would be great to detect when a transparent channel is fully opaque and remove it before saving the new image.

This speeds up encoding while decreasing file size by around 10%.

Implementing this feature would essentially be:

from PIL import Image

image = Image.open(original_filename)
if image.mode == 'RGBA':
    colors = image.getchannel('A').getcolors()
    if len(colors) == 1 and colors[0][1] == 255:
        image = image.convert('RGB')
image.save(destination)
@zerolab
Copy link
Collaborator

zerolab commented Jun 27, 2018

@BertrandBordage I think you meant this for wagtail/wagtail rather than wagtail/Willow ;)

@BertrandBordage
Copy link
Member Author

@zerolab No I didn’t, see #66 ;)

@zerolab
Copy link
Collaborator

zerolab commented Jun 27, 2018

I take it back, misread "open one on Willow about removing empty alpha channels". Sorry for the noise!

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

No branches or pull requests

2 participants