How to convert Unicode Indian language (Malayalam) to Image using PHP - php

Here is my php code for creating an image with text inside,
I used Malayalam language text but PHP generating an image like this "?????"
<?php mb_language('uni');
mb_internal_encoding('UTF-8');
header('Content-type: image/gif');
$text = 'മലയാളം ';
$font = 'mlkarthika.ttf';
$im = imagecreatetruecolor(160, 160);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 159, 159, $white);
imagettftext($im, 12, 0, 20, 20, $black, $font, $text);
imagegif($im);
imagedestroy($im);
?>
the font ML_ttkarthika is avalable in unicode font website, please help me

There are issues with ImageTTFText and Unicode.
You may want to look at this: PHP function imagettftext() and unicode

Related

Unicode characters is shuffled in php imagettftext

I am trying to print unicode characters in image using GD library
I have following code
$text = "கைவிடப்பட்ட";
$font = "arial.ttf";
$im = imagecreatetruecolor(2500, 500);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 2500, 500, $white);
imagettftext($im, 16, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);
Original text here is கைவிடப்பட்ட , but it prints as following , you can see that first letter is replaced.
Edit : I have tried 5 different fonts All results in same(online font preview is showing characters correctly) . whereas when I echo the string via php(from database) to browser, output is exactly same(கைவிடப்பட்ட), but why imagettftext is switching characters..
I am not sure about GD library and environment but I guess the issue is due to rendering. கை = combination of க + ை and the environment doesn't support the rendering for unicode while displaying. so either check any rendering solution or use non unicode fonts or do below workaround to tackle it in php.
$text = "கைவிடப்பட்ட";
$imgtext = tamilrender($text);
$font = "arial.ttf";
$im = imagecreatetruecolor(2500, 500);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 2500, 500, $white);
imagettftext($im, 16, 0, 10, 20, $black, $font, $imgtext);
imagepng($im);
imagedestroy($im);
function tamilrender($input)
{$input= preg_replace("/([க-ஹ])([ைேெ])/u", "$2$1", $input);
$input= preg_replace("/([க-ஹ])ொ/u", "ெ$1ா", $input);
$input= preg_replace("/([க-ஹ])ோ/u", "ே$1ா", $input);
return $input;}
Limitations of Unicode
The Unicode standard policy is to encode only characters, not glyphs. கை, includes a combination character onto க. of Tamil is treated a complex script that requires complex processing, and many software components don't properly handle it.
The best approach would be to find, or create, a php extension library which was written specifically for Tamil.

Imagettftext not producing correct results if I use the tamil lanuage ttf?

I am trying to write Tamil text on an image. I tried with different font files like latha.ttf and
Uni Ila.Sundaram-01.ttf files. The problem is that the vowels are getting misplaced. Please see the image for reference. Can anyone please suggest to me how to overcome this issue?
I use the code below:
<?php
header('Content-type: image/png; charset=UTF-8');
$text ='சுற்றிப்பார்க்க ';
$font = './fonts/UniIlla.ttf';
$im = imagecreatetruecolor(600, 300);
$bg_color = imagecolorallocate($im, 255, 255, 255);
$font_color = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 599, 299, $bg_color);
imagettftext($im, 20, 0, 10, 50, $font_color, $font, $font);
imagettftext($im, 20, 0, 10, 120, $font_color, $font, $text);
imagepng($im);
imagedestroy($im);
?>

PHP imagettftext() with korean characters are not working

I am trying to generate image with some text and I have wrote following code:
<?php
// Set the content-type
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = '준수';
// Replace path by your own font path
$font = 'fonts/Walkway Black RevOblique.ttf';
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
Now when I add text with English characters it works but when I used Korean characters is not working and getting this image.
Any idea how to display Korean text?
Thanks
Looks like Walkway Black RevOblique.ttf is not Korean font. Try to download and use Korean one.

Hindi text to Image - words not appearing properly PHP

I want to display hindi words on an image. Here is the code for it, it is working properly but it does not display "chote E ki matra" correctly. Example "अब हिन्दी" is displayed as : http://prntscr.com/8rj8mq
Also hindi.txt file contains these :
अब हिन्दी
मे टाइप
करना बहुत आसान है
Below php script read one line randomly and put it on image and display it. Can someone help me to correct this....
<?php
$word= file("hindi.txt");
$random = rand(0,2);
$text = $word[$random];
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
// Replace path by your own font path
$font = 'Mangal.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

How can I write arabic text in image in PHP

I tried to write an Arabic text in an image with PHP.
This is my code:
<?php
header("Content-Type: image/png; charset=utf8");
$im = imagecreatetruecolor(150, 30);
// Create some colors
$white = imagecolorallocate($im, 100, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
$font = 'tahoma.ttf';
$t = strrev('إن الدين عند الله الإسلام');
$text=utf8_encode($t);
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);
?>
Thank you.
What’s the output?
The strrev function is not unicode compatible
http://de2.php.net/manual/en/function.strrev.php
See the comments there for examples of unicode compatible ones.
Also see the imagettftext page,
I think the following comment is exactly what you need:
http://de2.php.net/manual/en/function.imagettftext.php#97767
This will work for you:
include("fagd.php");
use imagettftext($im, 20, 0, 10, 20, $black, $font, fagd($text));
fagd.php codes are here:
http://cdn.shirazitco.ir/fagd.txt

Categories