Convert Font?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
EAA
Posts: 1
Joined: 2018-08-16T14:08:56-07:00
Authentication code: 1152

Convert Font?

Post by EAA »

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:

Code: Select all

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:

Code: Select all

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:

Code: Select all

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:

Code: Select all

convert: unable to read font `/Library/Fonts//Nunito-Regular.ttf' @ warning/annotate.c/RenderType/872
I also tried putting quotes around the path and that didn't solve the issue. Any help would be much appreciated!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert Font?

Post by fmw42 »

Here is my same answer form stack overflow.

On some tools that make use of Imagemagick, the tools do not use the system ENV variable. So I have seen cases such as with PHP Imagick where Ghostscript cannot be located from the delegates.xml file. 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 PDF, 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

For example in all these lines and several others where there is command="&quote:gs&quot, replace gs with fullpath/to/gs

<delegate decode="pdf" encode="eps" mode="bi" command="&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sPDFPassword=&quot;%a&quot; &quot;-sDEVICE=eps2write&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;"/>

<delegate decode="pdf" encode="ps" mode="bi" command="&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=ps2write&quot; -sPDFPassword=&quot;%a&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;"/>

<delegate decode="ps" encode="eps" mode="bi" command="&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=eps2write&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;"/>

<delegate decode="ps" encode="pdf" mode="bi" command="&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pdfwrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;"/>
Post Reply