i'm trying to use fontawesome with imagemagick to display it's character as png ,
here is my code:
$size = '50';
$text = '';
$imgW = 200;
$imgH = 200;
$font = 'fontawesome-webfont.ttf';
$image = new Imagick();
$image->setResolution(144,144);
$draw = new ImagickDraw();
$draw->setFont($font);
$draw->setFontSize($size);
//$draw->setTextEncoding('UTF-8');
//$draw->setStrokeAntialias(true);
//$draw->setTextAntialias(true);
$image->newImage($imgW, $imgH, new ImagickPixel('none'));
$image->annotateImage($draw, 10, 45, 0, $text);
$image->setImageFormat('png');
header('Content-type: image/png');
echo $image;
but the image output looks like this

any idea how to fix such a encoding problem?
Using the example from this answer to ensure I had a UTF-8 string being passed into ImageMagick works for me. The only change from your code is the second line:
$size = '50';
$text = html_entity_decode("", ENT_COMPAT, 'UTF-8');
$imgW = 200;
$imgH = 200;
$font = 'fontawesome-webfont.ttf';
$image = new Imagick();
$image->setResolution(144,144);
$draw = new ImagickDraw();
$draw->setFont($font);
$draw->setFontSize($size);
//$draw->setTextEncoding('UTF-8');
//$draw->setStrokeAntialias(true);
//$draw->setTextAntialias(true);
$image->newImage($imgW, $imgH, new ImagickPixel('none'));
$image->annotateImage($draw, 10, 45, 0, $text);
$image->setImageFormat('png');
header('Content-type: image/png');
echo $image;
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