Does PHP imagemagick support with Unicode?
Posted: 2017-03-21T08:10:36-07:00
I'm using PHP imageMagick by enable php extention (http://php.net/manual/en/book.imagick.php) then I try to used below method to insert the Khmer Unicode characters to that images by using http://camvgo.com/image/fonts/Kh-Siemreap.ttf font but it is not correct
$strokeColor = "#000";
$fillColor = "red";
$backgroundColor = "#001";
$draw = new \ImagickDraw();
$text = "ប្រទេសកម្ពុជា";
$draw->setTextEncoding("UTF-8");
$draw->setFont(public_path('/image/fonts/KhmerOSMoul.ttf'));
$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);
$draw->setStrokeWidth(1);
$draw->setFontSize(36);
$draw->setTextAlignment(\Imagick::ALIGN_CENTER);
$draw->annotation(250, 75, $text);
$draw->setTextAlignment(\Imagick::ALIGN_CENTER);
$draw->annotation(250, 150, "ប្រទេសកម្ពុជា");
$draw->setTextAlignment(\Imagick::ALIGN_RIGHT);
$draw->annotation(250, 225, "ប្រទេសកម្ពុជា");
$draw->line(250, 0, 250, 500);
$imagick = new \Imagick();
$imagick->newImage(500, 500, $backgroundColor);
$imagick->setImageFormat("png");
$imagick->drawImage($draw);
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo "<img src='data:image/jpg;base64,".base64_encode($imagick->getImageBlob())."' />";
Result
$strokeColor = "#000";
$fillColor = "red";
$backgroundColor = "#001";
$draw = new \ImagickDraw();
$text = "ប្រទេសកម្ពុជា";
$draw->setTextEncoding("UTF-8");
$draw->setFont(public_path('/image/fonts/KhmerOSMoul.ttf'));
$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);
$draw->setStrokeWidth(1);
$draw->setFontSize(36);
$draw->setTextAlignment(\Imagick::ALIGN_CENTER);
$draw->annotation(250, 75, $text);
$draw->setTextAlignment(\Imagick::ALIGN_CENTER);
$draw->annotation(250, 150, "ប្រទេសកម្ពុជា");
$draw->setTextAlignment(\Imagick::ALIGN_RIGHT);
$draw->annotation(250, 225, "ប្រទេសកម្ពុជា");
$draw->line(250, 0, 250, 500);
$imagick = new \Imagick();
$imagick->newImage(500, 500, $backgroundColor);
$imagick->setImageFormat("png");
$imagick->drawImage($draw);
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo "<img src='data:image/jpg;base64,".base64_encode($imagick->getImageBlob())."' />";
Result