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

Padded thumbnails of JPGs aren't saved correctly #1925

Open
molokov opened this issue May 30, 2019 · 0 comments · May be fixed by #1992
Open

Padded thumbnails of JPGs aren't saved correctly #1925

molokov opened this issue May 30, 2019 · 0 comments · May be fixed by #1992
Labels

Comments

@molokov
Copy link
Contributor

molokov commented May 30, 2019

#1781 fixed the previous issue where creation of thumbnails would fail for JPGs as they couldn't be converted to RGBA.

However, there's still a problem if the thumbnail will be created with padding, as the new Image is created as RGBA on this line:

pad_container = Image.new("RGBA", pad_size, padding_color)

Thus, when the file save is tried, with filetype="JPEG" (and a .jpg file extension), this fails, causing the original image to be returned.
(On this line:

image = image.save(thumb_path, filetype, quality=quality, **image_info)
)

What we should probably do is for JPEGs where the thumbnail has padding is to save them as PNGs.

Possibly this can be done as simply as:

       if pad_size is not None:
            pad_container = Image.new("RGBA", pad_size, padding_color)
            pad_container.paste(image, (pad_left, pad_top))
            image = pad_container
            # Making thumbnail a png
            filetype = "PNG"
            thumb_path += ".png"
            thumb_url += ".png"

It's a little crude, as the thumbnail will have a ".jpg.png" extension, but it's the simplest fix I can think of.

Thoughts?

molokov added a commit to molokov/mezzanine that referenced this issue Jul 2, 2019
dbischof added a commit to dbischof/mezzanine that referenced this issue Jul 17, 2021
Forcing RBGA mode is not compatible with JPEG format. Instead follow the source image's mode. Fixes stephenmcd#1925
@dbischof dbischof linked a pull request Jul 17, 2021 that will close this issue
@jerivas jerivas added the bug label Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants