algoo / preview-generator

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

Previewing an image in jpg is rather slow #211

Open grignards opened 3 years ago

grignards commented 3 years ago

When all its dependencies are installed preview generator uses the ImagePreviewBuilderIMConvert builder. This builder then creates a temporary PNG image before giving it to the ImagePreviewBuilderPillow builder that converts the temporary png in jpeg. For a moderately sized image (around 8MB - 4000x2000 pixels) this takes 4-5 seconds. Converting the same directly with convert -resize does only take 0.6 seconds on the same computer.

Computing a preview should take around the same time as directly using convert.

PhilippeAccorsi commented 3 years ago
grignards commented 3 years ago
* Do we have an idea why we create png and after jpeg file and not directly the jpeg file ?

I think it all comes down to successive changes + a specific background management in ImagePreviewBuildPillow that could be easily replicated with ImagePreviewBuildWand.

* When you says `Converting the same directly`, its about creating PNG first and JPEG at end with convert-resize ?

No, without creating the PNG image (so with a command like convert original.jpg -resize 100x100 preview.jpg). Its the PNG image creation which is slow, encoding a PNG is not designed for speed.

lebouquetin commented 3 years ago

The right way to fix this would be to implement another builder which avoid this intermediate file and/or change priority in builders.

grignards commented 3 years ago

In fact there are 3 builders for images, and after a first look at it I think we could keep only one, ImagePreviewBuildWand as it seems to be able to support all the functionalities we need (background + currently supported file formats).