Recent Changes - Search:

Site.SideBar

Textimage

index.html

<img src='gen_image.php?text=<?= "abouzeid@ecse.rpi.EDU" ?>&bgcolor=grey'><br>
<img src='gen_image.php?text=<?= "mcdonald@unix.cie.rpi.edu" ?>&bgcolor=white'><br>

gen_image.php

<?php

header("Content-type: image/png");
$string = $_GET['text'];
$in_bgcolor = $_GET['bgcolor'];

// Create the image
$width = 250;
$height = 18;
$font_size = 11;
$top_margin = 13;

$im = imagecreatetruecolor($width, $height);

$grey = imagecolorallocate($im, 204,204,204);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);

if ($in_bgcolor == 'grey') {
  $bgcolor = $grey;
} else {
  $bgcolor = $white;
}

imagefilledrectangle($im, 0, 0, 399, 29, $bgcolor);

// Replace path by your own font path
$font = '/usr/share/fonts/bitstream-vera/Vera.ttf';

// Add the text
imagettftext($im, $font_size, 0, 0, $top_margin, $black, $font, $string);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);

?> 
Edit - History - Print - Recent Changes - Search
Page last modified on October 29, 2009, at 04:17 PM