PDA

View Full Version : PHP GD images



evileks
September 4th, 2006, 01:28 AM
Does anyone know any good tutorials on creating GD images? Every tutorial I seem to take doesn't work for some reason. I'm not sure it's if a server side issue or not, so if someone can post some code they know works for sure I could test that.

Otherwise I'm interesting in seeing how to use a font file in the image and how to load background images an what not. Any help is appreciated! :D

Jeff Wheeler
September 4th, 2006, 01:31 AM
http://php.net/gd

There's a lot of instructions there, plus an example.

teiz77
September 4th, 2006, 03:29 AM
I always use this funtion to create a button with text. You might be able to use some of the code.


<?
function createButton($label) {

// set filepath
$filename="path/to/images/".md5($label).".png";

// set path to font, only works with TTF
$font = "path/to/font.ttf";

// if the button already exists, just output it
if(file_exists($filename)) {

$imagesize = getimagesize($filename);
$outputstring = '<img src="/'.$filename.'" alt="'.addslashes($label).'" '. $imagesize[3].' id="btn_'.md5($label).'" />\',';
return $outputstring;

} else {

$font_size = 10;

// create the base image from an image ohn the server.
$image = imagecreatefrompng("path/to/button_base.png");

// set the color for the text
$text_color = imagecolorallocate($image, 165, 129, 155);

//put the text on the image
imagettftext($image, $font_size, 0, 8, 20, $text_color, $font, $label);

//save the image as png
$result = imagepng($image,$filename);

//destroy the temp image to free memory
imagedestroy($image);

// output the image
if($result) {
$imagesize = getimagesize($filename);
$outputstring = '<img src="/'.$filename.'" alt="'.addslashes($label).'" '. $imagesize[3].' id="btn_'.md5($label).'" />';
return $outputstring;
}

}
}
?>