algoo / preview-generator

generates previews of files with cache management
https://pypi.org/project/preview-generator/
MIT License
228 stars 50 forks source link

Add preview support in 'crop' mode #206

Open inkhey opened 3 years ago

inkhey commented 3 years ago

We should allow to support returning cropped version of a preview with a specific ratio. We need to clarify the mechanism.

Proposal:

To check:

inkhey commented 3 years ago

This method of pillow seems to be the way to go : https://pillow.readthedocs.io/en/stable/reference/ImageOps.html#PIL.ImageOps.fit

inkhey commented 3 years ago

Which cropping facility do we plan to offer? I've seen several service UIs which have the user define the cropped area himself (see github avatars for an example). Do we plan to do the same here for cover images? If yes the parameters would be a (x,y,width,height) rectangle, and we have to store this rectangle.

Originally posted by @grignards in https://github.com/tracim/tracim/issues/3904#issuecomment-736656114

If we decide to use ImagesOps .fit, it's doesn't provide x,y, so it depend what we do expect for usage for cropping. ImagesOps.fit is clearly better if we do need center stuff, (x,y) seems better if we need explicit ui support.

inkhey commented 3 years ago

I do think, one thing me can image is allowing for any jpeg preview, some pillow-based (i do think it's easier to rely on one tools for this one and not to be too generic for simple stuff) post-action like crop. see https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.crop Idea here is that we do not need to redefine crop for each image preview builder. It's a bit different from the proposal but this allow to handle all previews builder more easily