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.
2
Answers
If we consult this cloud functions system packages page, we see that ImageMagick was installed on the Ubuntu 18.04 images used for Cloud Functions. It also shows that ImageMagick is not present on the Ubuntu 22.04 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.
In Node version 18, the "convert" function cannot be found. To access it, you need to switch to version 16 of the runtime or use the ImageMagick library for Node. It’s unclear if support for "convert" will be offered again in the future or if this change is permanent. This is the solution I’ve found for the same problem I had in my project.