<?php

//
// t1demo.php
//
// Written by Marc Liyanage <liyanage@access.ch>
//


// Configuration


// Bitmap image dimensions
//
$IMG_WIDTH = 448;
$IMG_HEIGHT = 50;

// Font vector file, encoding file and size
//
$PSFONT_FILE = "/Library/WebServer/www.entropy.ch/software/macosx/php/AppleGarBoo.pfb";
$PSFONT_ENCODING_FILE = "/Library/WebServer/www.entropy.ch/software/macosx/php/IsoLatin1.enc";
$PSFONT_SIZE = 40;


// Need at least an empty string
//
$text = $_GET['text'];
if (!
$text) { $text = ""; }

// We expect UNICODE two-byte sequences for special characters,
// convert these to ISO in the input string
//
$text = preg_replace_callback("/[\x80-\xff][\x80-\xff]/", "convert_unicode_callback", $text);


$im = ImageCreate($IMG_WIDTH, $IMG_HEIGHT);

$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);

$font = ImagePSLoadFont($PSFONT_FILE);
ImagePSEncodeFont($font, $PSFONT_ENCODING_FILE);
$result = ImagePSText($im, $text, $font, $PSFONT_SIZE, $black, $white, 10, 38, 0, 0, 0, 16);
ImagePSFreeFont($font);


// Output the bitmap
//
Header("Content-type: image/png");
ImagePNG($im);
ImageDestroy ($im);



// Utility routine to convert  UNICODE to ISO-8859-1
//
function convert_unicode_callback ($doublebyte) {

    
$a = ord($doublebyte[0]{0});
    
$b = ord($doublebyte[0]{1});

    
$iso = (($a & 0x03) << 6) | $b;

    
$iso_char = chr($iso);

    return
$iso_char;

}



?>