algoo / preview-generator

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

Modify Wand builder and replace Imagemagick and Pillow with it #274

Closed a523 closed 3 years ago

a523 commented 3 years ago

https://github.com/algoo/preview-generator/issues/271 https://github.com/algoo/preview-generator/issues/253

PR Goal

Now the image__wand builder can work as the previous pillow builder, them passed the same test cases. And replace pillow and Imagemagick(command line) builder with wand builder.

Implemented solution

Now the imagewand builder is the default builder for image files, and also the imagewand builder instead of pillow builder when other builder call How to modify wand ? The following information is referenced: https://legacy.imagemagick.org/Usage/thumbnails/ https://stackoverflow.com/questions/25438402/python-wand-how-to-resize-keeping-aspect-ratio-and-filling-in-the-remaining-spac/25452063#25452063

Checkpoints

Expected :185 Actual :181


Only the`test_drawio_to_jpeg` test case failed, I think it was the case itself because the pillow builder also failed, if I can confirm, I will raise another PR to fix this test case.

- [x] The PR or the original issue contains a **short summary of the implemented solution**.
a523 commented 3 years ago

This modified Wand builder can pass the following tests:

tests/input/xcf/test_xcf.py test_to_jpeg fails with wand backend. #114 tests/input/svg/test_svg.py test_to_jpeg fails with wand backend. #115 tests/input/pdf/test_pdf.py test_to_pdf fails with imconvert backend. #116 tests/input/pdf/test_pdf.py test_to_jpeg fails with wand backend. #117 tests/input/txt/test_txt.py test_text_to_jpeg fail with wand and imconvert backend.

a523 commented 3 years ago

You need to reintroduce white background to not have weird and poor quality result for file with transparency.

fixed with commit 24463a1408196f98f4b785f637d6e7e15b612eb8 and 1af97cca408075c809a521000dea74e9c92b5575

You should probably deprecate both Pillow and ImageMagick (command line) builder

fixed with 7572911de8c5bb208e38fcb235e731f7f3d22db7 But you need to see if replacing pillow with Wand when handlingapplication/postscript files is your expectations. (Just need modify ImageMagick6 policy, then IM can work)

xcf and all raw image file are not supported by wand builder

fixed with 7572911de8c5bb208e38fcb235e731f7f3d22db7

There is no more quality/progressive/resample_algorithm options like in Pillow.

Yeah, quality/progressive/resample_algorithm there are all in ImageMagick.

I have created progressive JPEG image with -interlace Plane option, 6dbd8d31 But quality and resample_algorithm are used by default value, if we want we can specify a value also.

lebouquetin commented 3 years ago

You need to reintroduce white background to not have weird and poor quality result for file with transparency. fixed with commit 24463a1 and 1af97cc

@inkhey we lost several times the white background without to detect it before releasing. Do we have a dedicated test case? It would be interesting to have one in order to ensure quality based on automatic tests instead of developers watchfulness

a523 commented 3 years ago

You need to reintroduce white background to not have weird and poor quality result for file with transparency. fixed with commit 24463a1 and 1af97cc

@inkhey we lost several times the white background without to detect it before releasing. Do we have a dedicated test case? It would be interesting to have one in order to ensure quality based on automatic tests instead of developers watchfulness

@lebouquetin Yes, the test case is already included in the PR, commit :https://github.com/algoo/preview-generator/commit/1af97cca408075c809a521000dea74e9c92b5575