Announcement

Collapse
No announcement yet.

PHP script to convert text string to image

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP script to convert text string to image

    PHP script to write email address into a image

    I was after a php script that dynamically converts text to image and finally i decided to code on my own. It also does convert small length text to image like names, emails etc..

    This script automatically calculates the width of text into pixels inserts the PNG or gif image.


    Code:
    this is a string to < >
    To call the script for dynamically generating an image just use the html code

    Code:
    <img src="txt2img.php?text=<? echo $str ?>" border="0">
    and the code for the script is

    Code:
    //source for txt2img.php
     
    <?
     
    if(!isset($_GET['txt']))
    {
    exit();
    }
     
    header ("Content-type: image/png");
    $string = $_GET['txt'];
    $font   = 4;
    $width  = ImageFontWidth($font) * strlen($string);
    $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, $text_color);
    imagepng ($im);
    ?>

    Requirements:

    Apache
    PHP GD Library with PNG/GIF/JPEG support
    Attached Files

  • #2
    usefull, thanks

    Comment

    Working...
    X