Fast Image Resizing
On Recipeyak, we resize user-uploaded images to improve page performance (see “Image Optimization”).
We use Twicpic because the free tier is large, but I was curious how fast Twicpic was compared to the gold standard, Imgix.
resizing HTTP APIs
Twicpic and Imgix provide image resizing HTTP APIs. The first request for an image will trigger the service to resize and cache the image. The following requests will pull from the CDN.
In this comparison, Imgix took 1.5 seconds to resize an image, while TwicPics took 2.1 seconds.
The follow up requests from the CDN are significantly faster.
Imgix
https://recipeyak.imgix.net/IMG_9631.HEIC?w=100&h=100
trial | duration (seconds) |
---|---|
1 | 1.47 |
2 | 0.14 (cached) |
3 | 0.11 (cached) |
4 | 0.10 (cached) |
5 | 0.08 (cached) |
Twicpic
https://recipeyak-images.twic.pics/IMG_9631.HEIC?twic=v1/contain=100x100
trial | duration (seconds) |
---|---|
1 | 2.09 |
2 | 0.14 (cached) |
3 | 0.08 (cached) |
4 | 0.09 (cached) |
5 | 0.07 (cached) |
resizing CLIs
We can resize images ourselves with libaries like ImageMagick, sips, and libvips.
ImageMagick
convert -define jpeg:size=100x100 IMG_9631.HEIC -auto-orient \
-thumbnail 100x100 imagemagick.jpeg
trial | duration (seconds) |
---|---|
1 | 0.46 |
2 | 0.28 |
3 | 0.30 |
4 | 0.28 |
5 | 0.27 |
sips
sips --resampleWidth 100 IMG_9631.HEIC --out sip.heic
trial | duration (seconds) |
---|---|
1 | 0.38 |
2 | 0.35 |
3 | 0.36 |
4 | 0.34 |
5 | 0.36 |
libvips
vipsthumbnail IMG_9631.HEIC --size 100x100
trial | duration (seconds) |
---|---|
1 | 0.10 |
2 | 0.10 |
3 | 0.10 |
4 | 0.10 |
5 | 0.10 |
Conclusion
Twicpic is slow, but Imgix isn’t much better. I think generating thumbnails ahead of time would deliver the best user experience.