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

Feat: Does it support adjusting the quality of the generated image? #269

Open
a523 opened this issue Sep 14, 2021 · 2 comments
Open

Feat: Does it support adjusting the quality of the generated image? #269

a523 opened this issue Sep 14, 2021 · 2 comments

Comments

@a523
Copy link
Contributor

a523 commented Sep 14, 2021

Feature description and goals

We have a requirement to generate preview images for mobile use. By default , the user accesses a low quality compressed image, until he click the ’raw image‘ button.
So, I want to use the project not only to generate preview images but also to generate the compressed images, If the raw file is a image.
This way, I don't have to look for additional compressed libraries, because I think they should have almost the same dependencies, and I want to put them in the one project of mine.
That mean is I don't want to change the width and height of the image, but I want to change the quality (file size) of it

Prerequisites

@raphj
Copy link
Contributor

raphj commented Sep 28, 2021

Hello @a523, thank you for your feature request. Seems like it would be a useful thing to have.

@inkhey it seems like we could add a quality parameter to PreviewManager.get_jpeg_preview, what do you think?

You'd still need to pass the correct width and height though.

@inkhey
Copy link
Contributor

inkhey commented Sep 28, 2021

it's a good idea, but depending on the builder behind the parameter may have different meaning.

According to the current pillow builder, there is already few parameters that make sense for jpeg:

  • compression level aka quality
  • resampling algorithm

and maybe:

  • optimize
  • progressive
  • background color ?

# INFO - G.M - 2019-06-25 - some configuration for jpeg saved,
# see https://pillow.readthedocs.io/en/latest/handbook/image-file-formats.html?highlight=JPEG#jpeg
# optimize -> extra pass to select optimal encoded
# quality -> compression level from 1 to 100
# progressive -> permit to see a blured version of file instead of partial image when image
# is not fully downloaded, nice for web usage.
DEFAULT_JPEG_OPTIMIZE = True
DEFAULT_JPEG_QUALITY = 75
DEFAULT_JPEG_PROGRESSIVE = True
# Pillow algorithm use for resampling, bilinear is not the fastest but is fast
# enough, this permit good enough image (using faster algorithm return much more
# aliasing. see https://pillow.readthedocs.io/en/latest/handbook/concepts.html?highlight=Bilinear#filters
# for algorithm list.
DEFAULT_JPEG_RESAMPLE_ALGORITHM = PIL.Image.BILINEAR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants