Resizing an Image on the Server

From wiki.gpii
Jump to: navigation, search


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:

  1. Performant
  2. Compatible with our way of working:
    1. It should be possible to build a series of simple reusable components using the library.
    2. 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:

  1. sharp
  2. lwip
  3. jimp
  4. imagemagick

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:

  1. the docs are more complete
  2. the community is larger
  3. the release cadence seems more frequent and consistent
  4. 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.