Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2497
  • Last Modified:

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
HG




0
shang3000
Asked:
shang3000
  • 2
1 Solution
 
NopiusCommented:
> so my question is can that be done on linux ???

Yes.

> 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: http://php.net/gd creation of image from a string:

<?php

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);
imagepng($im);
imagedestroy($im);

?>


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.




0
 
ab_khadilkarCommented:
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){
 
	$width='80';
	$height='25';
	$characters='4';
	$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');
	
	
	/*imagestring($image,'5',20,5,$Code,$text_color);
	imagesetthickness($image,1);
	imagerectangle($image, 0, 0, 79, 24, $text_color);*/
	
	/* output captcha image to browser */
	header('Content-Type: image/gif');
	imagegif($image);
 
	/* Want to save image */
	//imagegif($image,"Code.gif");
	
	imagedestroy($image);
}
?>

Open in new window

0
 
NopiusCommented:
Probably font is missing or not located in GD specific font search path. Use an absolute filename like '/path/to/font.ttf'
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now