Thumbnailing images benchmark #60
quentin-bettoum
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello there,
Following this discussion, I've been trying to find the best way to thumbnail images using Vix/Image and benchmark it.
There are multiple ways to open and thumbnail an image.
The two most efficients are:
Image.thumbnail!(path)will open the image and thumbnail it directly and should automatically use some optimization to make it faster thanImage.open! |> Image.thumbnail!, but since you can also manually set a shrink option onImage.open, I was wondering if it could be faster to compute the optimal shrink-on-load by retrieving the image width and height, and then open it with this optimal value (considering we don't want the shrinked image to be less than 2 times the wanted thumbnail size to avoid aliasing).Here is a summary of what the results tells me.
Image.open! |> Image.thumbnail!is usually way waster than justImage.thumbnail(path). Up to 12 times faster on large jpeg inputs.TIFFWebPwhich I don't understand why. Either Vips is more optimized tothumbnail(path)forWebP, or thelibwebpscale-on-load is slower than theJPEGshrink-on-load.In these two cases,
Image.thumbnail(path)seems to be around 10% faster.The benchmark
Sources are available here
Results in HTML
Raw results
I also initially benchmarked with
MogrifyandImage.resize, but since they were significantly slower and because I wanted to debloat the results, I removed them from the benchmark.To see the efficiency of the functions used to compute the optimal shrink, I added a shrink CHEAT case where the optimal value is computed before the start of the benchmark.
This value is to be compared to the dynamic shrink where the value is computed while the benchmark is running.
If you want try the benchmark by yourself, you just have to put any image in the
imagesfolder, and the module will automatically try every option on each image for the benchmark.I did not upload all the sample images I used for the benchmark because I wanted to avoid to overload the repository since some images are quite large.
I didn't have the time to comment the code, but I believe the most interesting part of it are these functions which are used to compute the optimal shrink (for JPG) or scale (for WebP):
Also keep in mind that the use case tested in the benchmark is outputing thumbnailed image in JPG, WebP, and AVIF since these formats are supported on the web. The results could be different on another use case.
Beta Was this translation helpful? Give feedback.
All reactions