我不知道使用imagemagik的方法,但你可以从这里使用php-font-parser库:
https://github.com/Pomax/PHP-Font-Parser
具体来说,您可以分析所需字符串中每个字母的字体并检查返回值:
$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;
上面的代码来自字体解析器项目 fonttest.php类:
https://github.com/Pomax/PHP-Font-Parser/blob/master/fonttest.php