title: Specifying a font with the font family using ImageMagick
body: <p>Is it possible to render a font using the font family in ImageMagick?</p>
  
  <p>I have tried everything I can think of and nothing seems to work. I have done a lot of searching and I can't seem to find anything that addresses this specific issue.</p>
  
  <p>I am ultimately using PHP, but I have also tried using ImageMagick on the command line with no success. I am using ImageMagick 6.7.6 on linux. Here is what I have done so far.</p>
  
  <ul>
  <li>I have tested the fonts that ImageMagick reckognizes using the
  <code>identify -list font</code> command</li>
  <li>I have manually created a type.xml file based on the xml files that
  came installed on my system</li>
  <li>I have created a type.xml file using this script:
  <a href="http://www.imagemagick.org/Usage/scripts/imagick_type_gen" rel="nofollow noreferrer">imagick_type_gen</a></li>
  <li>I have tested with multiple font types: ttf, otf, pfb, ttc</li>
  </ul>
  
  <p>Here is the example output from <code>identify -list font</code> for some fonts I have tested with:</p>
  
  <pre><code>Font: DejaVu-Sans-Book
    family: DejaVu Sans
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: /usr/share/fonts/dejavu/DejaVuSans.ttf
  
  Font: Baskerville-Regular
    family: Baskerville
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: /usr/share/fonts/custom/Baskerville.ttc
  
  Font: Palatino-Roman
    family: Palatino
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: /usr/share/fonts/urw-fonts/p052003l.pfb
  
  Font: Honey-Script-Light
    family: Honey Script
    style: Normal
    stretch: Normal
    weight: 300
    glyphs: /usr/share/fonts/custom/HoneyScript-Light.ttf
  </code></pre>
  
  <p><br/>
  If I specify the full font name everything works as expected:</p>
  
  <pre><code>convert -pointsize 32 -font "Honey-Script-Light" label:'Testing' testing.png
  </code></pre>
  
  <p><img src="https://www.dropbox.com/s/ncomydv2mp23k9r/testing-right.png?raw=1" alt="Working"></p>
  
  <p><br/>
  However, when I try to use the font family (both listed by <code>identify -list font</code> and listed in type.xml) I get the default system font:</p>
  
  <pre><code>convert -pointsize 32 -family "Honey Script" label:'Testing' testing.png
  </code></pre>
  
  <p><img src="https://www.dropbox.com/s/zhg6k3cxjxvzd1l/testing-wrong.png?raw=1" alt="Not Working"></p>
  
  <p><br/>
  I have also tried specifying all of the font's parameters and it again does not work:</p>
  
  <pre><code>convert -pointsize 32 -stretch Normal -style Normal -weight 300 -family "Honey Script"   label:'Testing' testing.png
  </code></pre>
  
  <p><br/><br/>
  When I do a similar process through PHP, it actually returns an error as soon as I try to set the font family of the draw object.</p>
  
  <pre><code>$draw-&gt;setFontFamily('Honey Script');
  </code></pre>
  
  <p>This is the error that gets thrown:</p>
  
  <pre><code>PHP Fatal error:  Uncaught exception 'ImagickDrawException' with message 'Unable to set font family; parameter not found in the list of configured fonts
  </code></pre>
  
  <p><br/><br/>
  Just like the command line option, if I specify the full font name, the image is rendered properly.</p>
  
  <pre><code>$draw-&gt;setFont('Honey-Script-Light');
  </code></pre>
  
  <p><br/><br/>
  From everything I have found about how to configure a font to be used with ImageMagick, the fonts are indeed configured. Why can't I select the fonts based on the font family?</p>
  
  <p>Is this possibly an undocumented bug? Is there something I am missing?</p>
  
  <p>I realize that I could simply specify the full font name and be done with it, but there is a reason specific to my project that make it much better to specify the font family.</p>
  
  <p>Why would specifying the font family be an option if it does not work? This is what ImageMagick says regarding the font family option:</p>
  
  <blockquote>
    <p>This setting suggests a font family that ImageMagick should try to use
    for rendering text. If the family can be found it is used; if not, a
    default font (e.g., "Arial") or a family known to be similar is
    substituted (e.g., "Courier" might be used if "System" is requested
    but not found).</p>
  </blockquote>
  
  <p>Any ideas are very welcome. I am pretty much stuck at this point.</p>
  
  <p><br/>
  <strong>EDIT:</strong><br/>
  The main reason I would prefer to use font families rather than fully named fonts is because of the input I am processing. I receive files from a third party that need to be processed. These files specify fonts as:</p>
  
  <pre><code>font-family="Honey Script" font-style="Normal" font-stretch="Normal" font-weight="300"
  </code></pre>
  
  <p>If I had to specify the exact font name based on that information I would need to create a mapping for every possible combination of font family and attributes to the exact font name. That would be very difficult to maintain as hundreds of fonts are added to the system.</p>
  
  <p>It seems to me that there must be a way to get ImageMagick to retrieve the exact font based on all the available details about the font as listed above.</p>
  
  <p>If that is not possible then why would ImageMagick have the option to specify font family at all?</p>