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

Add JPEG quality option #186

Open
timomeara opened this issue Mar 12, 2018 · 11 comments
Open

Add JPEG quality option #186

timomeara opened this issue Mar 12, 2018 · 11 comments

Comments

@timomeara
Copy link

something like this would be great:
'large': {'width': 354, 'height':270, 'crop':True, 'resample':True, 'jpg_quality':75}

@timomeara
Copy link
Author

#187

i hope this is better.

@codingjoe
Copy link
Owner

@timomeara really appreciated your effort here, I just don't want to rush this. I agree that JPEG is probably the most likely of files this library supports.

I think this could go two different ways. Ether you have attributes per mime type

img = stdimage.StdImageField(variations={}, jpeg_attrs={}, png_attrs={})

or
have a subclass of the field that is JPEG only.

Both solutions have their pros and cons I guess. Maybe there is also a third one. Let me know what you think.

@timomeara
Copy link
Author

hey-
np. we are going to use this in an app that goes live 4/1 so i'm motivated ;)

i'm not sure i understand the problems with either of the approaches i've submitted.

i get the png does not support the quality param... but it just ignores it... it's a little ambiguous, but it won't break anything.

a jpg_quality attrib is less ambiguous but that didn't fly either ;)

what other attribs would you put in the png{} ?

i'm setting optimize=True on everything, but i think that's what you were doing too, no?

tmo

@codingjoe
Copy link
Owner

ok, here is what I would recommend to do. I would create a subclass, a JPEG field that always saves the variations as JPEG. For this field you can of course add attributes that are JPEG specific.

@codingjoe
Copy link
Owner

Please don't be discouraged. I do see the need for this feature. I am just very careful with adding new features, since I have to maintain them ;)

@codingjoe
Copy link
Owner

to be a bit more precise what I am suggesting is:

class JpegImageField(StdImageField):
    """Do whatever you want."""
    pass

@marojenka
Copy link

marojenka commented Apr 11, 2018

hi,
rendering (some) variations as jpeg would be really nice option I believe. Page full of png thumbnails makes me sad. Clearly it's additional hassle to maintain, so it's up to you to decide.
Defining own class is not a big deal, sure, and I might be missing something but the only way to mess with saving variations is to hack render_variation method which is not really friendly due to it's size.
As for now I copy whole function to my custom class if I need it.

@codingjoe
Copy link
Owner

I agree fully. I am just waiting for someone to submit a patch ;)

@marojenka
Copy link

@codingjoe well this is how I see it:
#188

@marojenka
Copy link

After pull #188 I use something like this to force all variations to be JPEGs.

    @classmethod
    def process_variation(cls, variation, image):
        img, kargs = super().process_variation(variation, image)
        img = img.convert('RGB')
        kargs['format'] = 'JPEG'
        return (img, kargs)

    @classmethod
    def get_variation_name(cls, file_name, variation_name):
        std_name = super().get_variation_name(file_name, variation_name)
        path, _ = os.path.splitext(std_name)
        return path + '.jpeg'

By the look of it I think may be actual resampling also should be separate function.

@codingjoe
Copy link
Owner

There is a JPEGField now, I would be open to adding a quality arguments to that.

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