PHP script to convert String into a image

This is just a simple script that will get string from user and convert it to image then output it. You may use it  to convert your text name, email address, web site url, etc. This script automatically calculates the width of text into pixels inserts the PNG or gif image.

In this script we use three files – Index.php, index2.php, and text_image.php.
Step 1: Create a form to pass string in the index.php. Some thing like this:

Use the below code:

<form action=”index2.php” method=”post”>

<label for=”email”>Email:</label>
<input type=”text” name=”email” id=”email” value=”” /><br />
<input type=”submit” value=”Convert” />


Step 2: Copy and peste the below code to text_image.php

$string_email = $_GET[’email’];

header (“Content-type: image/png”);
$font   = 5;
$width  = ImageFontWidth($font) * strlen($string_email);
$height = ImageFontHeight($font);
$im = @imagecreate ($width,$height);
$background_color = imagecolorallocate ($im, 255, 255, 255); //white background
$text_color = imagecolorallocate ($im, 0, 0,0);//black text
imagestring ($im, $font, 0, 0,  $string_email, $text_color);
imagepng ($im);

Step 3: Just showing the text converting to image. To call the script for dynamically generating an image just use the below html code :

<img src=”text_image.php?email=<?php echo $string_email; ?>” border=”0″>


You can also download the script from here


Wish You will like it.

Author Info

Shah Alom

Hi, This is Mohammad Shah Alom, My passion is Programming & Web Development. I am Founder of Micro Solutions Bangladesh. My Facebook profile shahalom1983 & Twitter Profile shahalom_83