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

Adding fix for transparent pngs #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rmaglio
Copy link

@rmaglio rmaglio commented Jan 23, 2019

The Pillow library was changed where it throws an error when you save a transparent PNG as a JPG because there was no place for the transparent channel to be mapped to in a jpg so the transparent channel is dropped. To avoid the error you need to explicitly convert the PNG to use RGB and then save it.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.857% when pulling dd86ced on rmaglio:master into e8b1679 on yu-liang-kono:master.

@shoeb-a-sabur
Copy link

shoeb-a-sabur commented Apr 1, 2020

Is the repo maintainer active? Merging this would have saved me a few hours of searching and trying stuff. Although I solved it a bit differently by doing a shallow copy and adding a check to make the conversion only when PNG with alpha channel is detected

`

    working_image = copy.copy(self.context.modules.engine.image)

    if working_image.mode in ('RGBA', 'LA'):
        logging.debug("RGBA found and converting")
        working_image = working_image.convert("RGB")

    bio = BytesIO()
    working_image.save(bio, 'JPEG')
    return bio.getvalue()

`

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.

None yet

4 participants