I'm using Imagick to generate simple logos, which are just text on a background.
I'm usually looping through all available fonts, to present the user with a choice of different renderings for every font (one image per font).
The problem is, some fonts don't support the ASCII characters (I think they've been designed for a given language only). And I guess that some of the fonts which support ASCII characters, will fail with non-ASCII characters as well.
Anyway, I end up with images such as these:
Is there a programmatic way in Imagick
to tell whether a given font supports all the characters in a given string?
That would help me filter out those fonts which do not support the text the user typed in, and avoid displaying any garbage images such as the ones above.
I don't know a way using imagemagik, but you could use the php-font-parser library from here:
https://github.com/Pomax/PHP-Font-Parser
Specifically, you can parse a font for each letter in your required string and check the return value:
$fonts = array("myfont.ttf");
/**
* For this test, we'll print the header information for the
* loaded font, and try to find the letter "g".
*/
$letter = "g";
$json = false;
while($json === false && count($fonts)>0) {
$font = new OTTTFont(array_pop($fonts));
echo "font header data:\n" . $font->toString() . "\n";
$data = $font->get_glyph($letter);
if($data!==false) {
$json = $data->toJSON(); }}
if($json===false) { die("the letter '$letter' could not be found!"); }
echo "glyph information for '$letter':\n" . $json;
Above code comes from the font parser projects fonttest.php class:
https://github.com/Pomax/PHP-Font-Parser/blob/master/fonttest.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With