how to convert text to images in linux

Posted on 2007-07-24
Last Modified: 2012-06-27
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

Question by:shang3000
    LVL 27

    Accepted Solution

    > 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.

    LVL 2

    Expert Comment

    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

    LVL 27

    Expert Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now