Resizing an Image on the Server
In preparing to add image support to the Unified Listing, we need to evaluate the options for resizing images on the server, so that we can serve up "thumbnail" versions when provided with larger originals.
My starting assumption was that we needed something that supported common image formats as inputs, especially those we already have in our collection of images coming from EASTIN. I prepared a report to confirm our holdings, we have a mixture of PNG, GIF, and JPEG images, with one webp file. As webp is not widely supported within browsers, I considered that an optional requirement.
I also assumed that we wanted something:
- Compatible with our way of working:
- It should be possible to build a series of simple reusable components using the library.
- It should not require us to support additional technologies for either the code or tests.
When looking for a library, I did a number of google searches and npm searches, and looked through a range of candidates. A few names kept coming up:
Each of these supports the required formats as inputs and outputs, so there were no immediate disqualifications.
The initial preference is for something that works in node. Of the node libraries, sharp quickly stood out. It is the fastest by far, see their performance docs for details. Sharp also gives more of an impression of maturity as a project/community than "jimp" or "lwip", in that:
- the docs are more complete
- the community is larger
- the release cadence seems more frequent and consistent
- the API seems more complete
Imagemagick is a classic that I used productively in the late 90s, but in addition to being slower and less well maintained, it would increase the deployment and test complexity without adding any value.
In summary, sharp seems to be the best starting point for image resizing.