<?php
    // sample to print out a string as png picture. 
    // to view source call with: gd_text.php?viewsource=1
    // call f.e. with: gd_text.php?b=4&trans=1&s=teststring
    // v0.12 20-Sep-2004, by G. Knauf <efash@gmx.net>
    if ($_GET['viewsource']) {
        echo highlight_string(file_get_contents($_SERVER['SCRIPT_FILENAME']));
        die;
    }
    extension_loaded('gd') or die ("Error: GD extension not loaded!"); 
    if ($_GET['s'])
        $string = $_GET['s'];
    else
        $string="TEST it!";
    $font = $_GET['fs'];
    if ($font < 1 || $font > 5)
        $font = 3;
    if ($_GET['b'])
        $border = $_GET['b'];
    else
        $border = 8;
    $s_len = strlen($string);
    $x = ImageFontWidth($font) * $s_len;
    $y = ImageFontHeight($font);
    $im = @ImageCreate ($x + (2 * $border), $y + (2 * $border));
    $bg_color = ImageColorAllocate ($im, 250, 255, 205);
    $fg_color = ImageColorAllocate ($im, 233, 14, 91);
    if ($_GET['trans'])
        ImageColorTransparent($im, $bg_color);
    ImageString($im, $font, $border, $border, $string, $fg_color);
    Header("Content-type: image/png");
    ImagePng($im);
    ImageDestroy($im);
?>
Published in: PHP
Download

Related snippets