I am trying to add a hindi text to an image using PHP GD and the text is being converted to squares, I think this is happening, php gd is not supporting hindi text.
Please tell me how to solve this issue or is there any other way to add hindi text to an Image.
This is the code I am using:
//Set the Content Type
header('Content-type: image/jpeg');
// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('temp/mango.jpg');
// Allocate A Color For The Text
$white = imagecolorallocate($jpg_image, 255, 255, 255);
$black = imagecolorallocate($jpg_image, 0,0,0);
$font = dirname(__FILE__) . '/font/opensans.ttf';
// Set Text to Be Printed On Image
// Print Text On Image
imagettftext($jpg_image, 25, 0, 75, 300, $white, $font, "आम फलो का राजा है। ");
// Send Image to Browser
imagejpeg($jpg_image);
// Clear Memory
imagedestroy($jpg_image);
Result I am Getting :
For Hindi Letters you need to use utf8_encode() to encode hindi letters to PHP context.
imagettftext($jpg_image, 25, 0, 75, 300, $white, $font, utf8_encode("आम फलो का राजा है। "));