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

ImageOps.expand distorts image and converts png to grayscale #5375

Closed
glisignoli opened this issue Apr 1, 2021 · 5 comments · Fixed by #5562
Closed

ImageOps.expand distorts image and converts png to grayscale #5375

glisignoli opened this issue Apr 1, 2021 · 5 comments · Fixed by #5562
Labels
Bug Any unexpected behavior, until confirmed feature. Palette

Comments

@glisignoli
Copy link

What did you do?

Resize an image and add a black border

What did you expect to happen?

Image would be resized with a black border

What actually happened?

Image is distorted converted to grayscale, resized and border added

What are your OS, Python and Pillow versions?

  • OS: Fedora 33
  • Python: 3.8.6
  • Pillow: 8.1.2
git clone https://github.com/hampusborgos/country-flags.git
cd country-flags/png1000px
from PIL import Image, ImageOps
i = Image.open('./bo.png')
i = i.resize((128,96))

# File saves correctly
i.save('./test.png')

i = ImageOps.expand(i, border=10, fill='black')

# File gets converted to grayscale and is distorted
i.save('./test.png')
@radarhere
Copy link
Member

The bug is because the image is in P mode. If you are interested in an immediate solution, convert it to RGB.

from PIL import Image, ImageOps
i = Image.open('./bo.png')
i = i.resize((128,96))

# File saves correctly
i.save('./test.png')

i = ImageOps.expand(i.convert("RGB"), border=10, fill='black')

# File gets converted to grayscale and is distorted
i.save('./test.png')

@radarhere radarhere added the Bug Any unexpected behavior, until confirmed feature. label Apr 1, 2021
@glisignoli
Copy link
Author

Thanks! Would this still be classified as a bug? I think it could be considered one?

@radarhere
Copy link
Member

Yes, this is still a bug that we should address.

@ahammadshawki8
Copy link

I faced the same problem and solved it by converting it to RGB, Thanks.

@radarhere
Copy link
Member

#5551 stopped the output from being grayscale, but the colors were wrong.
#5552 fixed the colors, but accidentally shifted the border slightly.

#5562 fixes the border position, resolving this.

test

@mergify mergify bot closed this as completed in #5562 Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature. Palette
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants