6

I'm integrating an ImageMagick command into a Firebase Function written in Node.js. I already have Ghostscript installed and have a full list of fonts available:

convert -list font

Path: /usr/local/Cellar/imagemagick/7.0.8-10/etc/ImageMagick-7/type-apple.xml
  Font: AndaleMono
    family: Andale Mono
    style: Undefined
    stretch: Undefined
    weight: 0
    glyphs: /Library/Fonts//Andale Mono.ttf
  Font: AppleChancery
    family: Apple Chancery
    style: Undefined
    stretch: Undefined
    weight: 0
    glyphs: /Library/Fonts//Apple Chancery.ttf
  Font: AppleMyungjo
    family: AppleMyungjo
    style: Undefined
    stretch: Undefined
    weight: 0
    glyphs: /Library/Fonts//AppleMyungjo.ttf

Here's my code:

exec(`convert ${tempFilePath} -font /Users/emma/Library/Fonts/Nunito-Regular.ttf -fill white -pointsize 60 -gravity center -draw "text 0,300 'this is a label'" ${tempFilePath}`, {stdio: 'ignore'}, (err, stdout) => {
         if (err) {
             console.error('Failed to label image.', err);
             reject(err);
         } else {
             resolve(stdout);
         }
});

I also tried:

exec(`convert ${tempFilePath} -font Arial -fill white -pointsize 60 -gravity center -draw "text 0,300 'this is a label'" ${tempFilePath}`, {stdio: 'ignore'}, (err, stdout) => {
       if (err) {
          console.error('Failed to label image.', err);
          reject(err);
       } else {
          resolve(stdout);
       }
});

The error I'm getting is:

convert: unable to read font `/Library/Fonts//Andale' @ warning/annotate.c/RenderType/872
EAA
  • 121
  • 1
  • 11
  • What is in `${tempFilePath}`? – Mark Setchell Aug 16 '18 at 15:43
  • Try changing `300` to `0` in case your picture is less than 600 pixels tall. – Mark Setchell Aug 16 '18 at 15:44
  • @MarkSetchell ${tempFilePath} is just the path of the image I'm converting. I downloaded it earlier in the code to a temp directory. – EAA Aug 16 '18 at 16:14
  • You said you used `Nunito-Regular` or `Arial` but the error message is about `Andale` - did you really give matching code and error messages? I guess your font file has a space in its name, try enclosing it in double quotes. – Mark Setchell Aug 16 '18 at 16:41
  • Try using the full path to the font file rather than just the font name. Does that work? – fmw42 Aug 16 '18 at 17:53
  • @MarkSetchell All the error messages were the same regardless of what I wrote there, but let me try the double quotes – EAA Aug 16 '18 at 17:53
  • @fmw42 I tried that, but it didn't work either – EAA Aug 16 '18 at 17:54
  • 1
    On some tools that make use of Imagemagick, they do not use the system ENV variable. So I have seen cases such as with PHP Imagick where it cannot locate the Ghostscript. In those cases the solution was to put the full path to Ghostscript where it uses `gs` in the delegates.xml file of Imagemagick for those lines such as PS, EPS that list `gs`. I know nothing about Firebase or Node, but that is something to look into. See https://www.imagemagick.org/script/resources.php for delegates.xml and its possible locations. Mine is at /usr/local/etc/ImageMagick-6/delegates.xml – fmw42 Aug 16 '18 at 19:04
  • @fmw42 - That did it for me. gs could not be found, probably related to a software update. Did a 'brew install gs' on MacOS and it fixed it. – cwingrav Jan 02 '20 at 15:05

1 Answers1

1

As per @fmw42 suggested:

On some tools that make use of Imagemagick, they do not use the system ENV variable.

So I have seen cases such as with PHP Imagick where it cannot locate the Ghostscript.

In those cases the solution was to put the full path to Ghostscript where it uses gs in the delegates.xml file of Imagemagick for those lines such as PS, EPS that list gs.

See https://imagemagick.org/script/resources.php for delegates.xml and its possible locations. Mine is at /usr/local/etc/ImageMagick-6/delegates.xml

So the possible solution is to install gs tool.

On MacOS: brew install gs.

Related post: https://imagemagick.org/discourse-server/viewtopic.php?t=34911.

kenorb
  • 155,785
  • 88
  • 678
  • 743