-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
There's (potentially) a big performance win if you can use thumbnail rather than thumbnail_image.
The thumbnail operation combines load and resize in a single step, so it can exploit the various shrink-on-load hacks that many image format libraries support. These can give dramatic speedups and improve quality.
For example, with a typical 6k x 4k RGB JPG from a smartphone:
$ /usr/bin/time -f %M:%e vips thumbnail_image theo.jpg thumb.jpg 512
230976:0.19
ie. 231mb of ram, 0.2s of elapsed time, on this Ubuntu 24.10 machine with libvips 8.16. If I use thumbnail I see:
$ /usr/bin/time -f %M:%e vips thumbnail theo.jpg thumb.jpg 512
79880:0.09
Now it's 80mb of ram and 0.09s of elapsed time, three times less memory and twice as quick.
In fact it's better than that, since the vips CLI uses some ram and takes some time to start and stop:
$ /usr/bin/time -f %M:%e vips > /dev/null
30728:0.03
So 30mb of ram and 0.03s to start and stop. If we subtract this overhead and compare, thumbnail needs 4x less memory and is 4x faster.
For a possible implementation, you could:
- in
FilePathImageDecoder.php, as well as opening the image withnewFromFile, you could also save the input filename in some secret member variable - in all processing steps except resize, you could clear this secret filename member
- in
ResizeModifier.php, you could see if the filename was set and callthumbnailrather thanresize
The idea being that intervention could recognise the magic open, resize sequence (surely very common) and substitute thumbnail in this case. I expect there's a better way to implement this!
You can do something similar for memory and pipe sources with thumbnail_buffer and thumbnail_source.