Search code examples
firebasegoogle-cloud-functionsimagemagickimagemagick-convert

Cloud Functions for Firebase ImageMagick convert: not found


In my Node.js functions, I have code that calls convert, which used to work but is now failing because it cannot find ImageMagick's convert command. What happened? Is there a way around this?

const args = [tempIn, "-thumbnail", "'258x258>'", tempOut];
spawnSync("convert", args, { encoding: "utf8", shell: true }); // error
// stderr: /bin/sh: 1: convert: not found

I'm aware that this command was changed to magick in ImageMagick version 7. It doesn't work with that command either. I'm also aware of supposedly current documentation that indicates the convert command is still installed.

ImageMagick and its command-line tool convert are included by default within the Google Cloud Functions execution environment for most of the runtimes. For PHP, you may need to do some manual configuration.

I also see there are questions on StackOverflow from 2019 mentioning npm packages such as GraphicsMagick for use with Firebase Functions. However, these packages presuppose the existence of the ImageMagick on the base system, which does not appear to be the case for me.

Lastly, I'm aware that there are and have been Firebase extensions for creating thumbnails, but for various reasons, I cannot use them.


Solution

  • If we consult this cloud functions system packages page, we see that ImageMagick was installed on the Ubuntu 18.04 (Node 16) images used for Cloud Functions. It also shows that ImageMagick is not present on the Ubuntu 22.04 (Node 18) images, which are presumably what it uses as I write this in 2023.

    So the answer to what happend is that ImageMagick was deleted. In terms of what to do about it, unfortunately we are left to use the previous solutions for building and delivering our own binaries into cloud functions.

    Finally, maybe consider using the npm package sharp instead.