Open timomeara opened 6 years ago
i hope this is better.
@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.
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
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.
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 ;)
to be a bit more precise what I am suggesting is:
class JpegImageField(StdImageField):
"""Do whatever you want."""
pass
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.
I agree fully. I am just waiting for someone to submit a patch ;)
@codingjoe well this is how I see it: https://github.com/codingjoe/django-stdimage/pull/188
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.
There is a JPEGField
now, I would be open to adding a quality arguments to that.
something like this would be great: 'large': {'width': 354, 'height':270, 'crop':True, 'resample':True, 'jpg_quality':75}