how to convert text to images in linux

hi all,
I have a client that want to make unicode text coming from data base converted to image the text is in arabic and the application is for publish (news paper stuff) so the letter have more than shape according to it's place in the word (start of the word , middele of the word or end of the word or as a single letter  ) and he want all of that to be done in a web solution and the generation to be done  dynamically.
so my question is can that be done on linux ??? if the answer is yes what is the  language that can do this ??? (java, perl,ruby, python, php or other) and  where can I get a working example (free open source )in that topic???
I hope you can help me in that and I need your help badly and urgently and ideia or direction is welcomed
best Regards

Who is Participating?
> so my question is can that be done on linux ???


> if the answer is yes what is the  language that can do this ???

PHP, perl, python, ruby. You only should have support of libgd compiled and installed to your language. That's possible for most of listed languages. Just search google for 'libgd {ruby|perl|php|python|...}" you will find references how to install it for your language/OS/distribution.

As an example, for PHP: creation of image from a string:


header("Content-type: image/png");
$string = $_GET['text'];
$im     = imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px     = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);


GD supports unicode, to use other charset, read a comment (from the link above)

"How to using GD out put  chinese Characters (BIG 5 or GB2312).
the following code shows you how to using gd display chinese Characters.
there is a funcation called by ImageTTFText.
since gd dose not support GB2312/big5 but unicode."

He recommends how to convert from other charset to unicode.

Also .TTF font for Arabic may be required. But all problems are resolvable.

How to get image from text on linux machin PHP
Hi frnds ;
i hav one problem regarding linux .I write code which takes input as a string and give output as a .gif image in PHP. It works fine on windows machin but when i try it on linux i dont get any image file .
Please give me some expert comments which help to solve my problem
I am attaching the code here which is in PHP
the font file mentioned in this is in same folder that of script.
$Code = isset($_GET['Code']) ? $_GET['Code'] : '7399';
$gif = gifCreator($Code);
function gifcreator($Code){
	$font = 'trebuc.ttf';
	print realpath(basename(getenv("DOCUMENT_ROOT")));
	$docRoot = getenv("DOCUMENT_ROOT");
	echo "$docroot";
	/* font size will be 75% of the image height */
	$font_size = $height * 0.75;
	$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
	/* set the colours */
	$background_color = imagecolorallocate($image, 255, 255, 255);
	$text_color = imagecolorallocate($image, 20, 40, 100);
	$noise_color = imagecolorallocate($image, 100, 120, 180);
	/* generate random dots in background */
	for( $i=0; $i<($width*$height)/15; $i++ ) {
		imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
	/* generate random lines in background 
	for( $i=0; $i<($width*$height)/250; $i++ ) {
		imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
	/* create textbox and add text */	
	$textbox = imagettfbbox($font_size, 0, $font, $Code) or die('Error in imagettfbbox function');
	$x = ($width - $textbox[4])/2;
	$y = ($height - $textbox[5])/2;
	imagettftext($image, $font_size, 0, $x, $y, $text_color, $font, $Code) or die('Error in imagettftext function');
	imagerectangle($image, 0, 0, 79, 24, $text_color);*/
	/* output captcha image to browser */
	header('Content-Type: image/gif');
	/* Want to save image */

Open in new window

Probably font is missing or not located in GD specific font search path. Use an absolute filename like '/path/to/font.ttf'
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.