I am working with Pillow, Django, and django-imagekit.
I am looking to be able to have a profile picture model field (probably using the ProcessedImageField
class from imagekit) that will take any image, convert to JPEG, crop it to 150x150, and make its file size 5KB.
The first two are easy:
profile_picture = imagekit.models.ProcessedImageField(upload_to=get_profile_picture_file_path,
format='JPEG',
processors=[ResizeToFill(height=150, width=150)]
)
But how can I ensure the file size is 5KB? I could use something like the options={'quality': 60}
parameter in ProcessedImageField
, but that seems to be only relative to the original file size (to my knowledge).
Solutions don't have to use django-imagekit, but that would be preferred.