Skip to content
March 24, 2008 / ranacse05

Convert String to Image


In facebook.com we see a nice thing,that is when u try to edit ur profile the e-mail address becomes image ! I mean u just type string and that becomes image.Here is the code which can convert string into image.

$date = ‘Raquibul Islam’;

$img = imagecreatetruecolor(100,25);
$bgcol = imagecolorallocate($img,255,255,255);
$hatcol = imagecolorallocate($img,rand(128,255),rand(128,255),rand(128,255));
$headcol = imagecolorallocate($img,255,225,205);
$bodycol = imagecolorallocate($img,0,0,0);
$eyecol = imagecolorallocate($img,rand(100,200),rand(0,128),rand(128,255));
$mouthcol = imagecolorallocate($img,rand(128,255),0,0);
imagefill($img,0,0,$bgcol);
imagestring($img,2,8,4,$date,$bodycol);
imagesetthickness($img,1);
imagerectangle($img,0,0,99,24,$bodycol);
header(“Content-type: image/png”);
imagepng($img);
imagedestroy($img);

Just copy the code and paste it into a .php file and run it.The string from $data will represent as an image. 🙂

Advertisements

8 Comments

Leave a Comment
  1. Nuhil / Mar 26 2008 1:20 am

    I’ve tried that but there was problem with ‘Call to udefined function …..’
    And there shows a Syntax Error on Line 2.

    Whts may be the problem in my script or config?

  2. ranacse05 / Mar 26 2008 5:19 am

    @Nuhil
    When ever u just copy and paste the code from blog please take a close look to the quote .

  3. Ankur Rana / Sep 13 2008 2:02 am

    Thanks …. it’s working.

    But could you tell me how to convert a textfile into image… when i try to include a file in it give the error in image.

  4. mohamed / Jul 7 2009 4:51 pm

    hey
    thanx for the subject

    can you please tell me how to increase the string size so it appears in large font?

    thank u

  5. M.Ihsan Fadli / Aug 24 2009 2:27 am

    Owh……….THank You Very Much….. Akhirnya DaPet Juga Scriptnya~

  6. Jagruti / Sep 16 2009 12:03 pm

    I want to convert Hindi txt stored in database to image , how can I do it?

  7. pradeep / Jan 8 2010 2:12 pm

    it not working

    • ranacse05 / Jan 14 2010 3:48 pm

      u need the GD lib for this.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: