Forum Moderators: coopster
<?php header("Content-type: image/gif"); // changed this to gif
$font = '/Library/Fonts/Chalkboard.ttf';
// This script worked as : imagecreate(110, 110);
$im = ImageCreateFromGIF("/TemplateButton.gif");
// Create some colors
// transparent may only work for gif?
//$colorTransparent = imagecolortransparent($im);
$background = imagecolorallocate($im, 255, 255, 255);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
$red = imagecolorallocate($im, 255, 57, 140);
$MainButtonShadow = imagecolorallocate($im, 0, 0, 153);
$MainButtonLight = imagecolorallocate($im, 51, 51, 255);
// this is standard submmit string stuff, I know it works!
if(isset($_GET['TextNumber'])){$TextNumber = $_GET['TextNumber'];}
elseif(isset($_POST['TextNumber'])){$TextNumber = $_POST['TextNumber'];}
elseif(isset($_REQUEST['TextNumber'])){$TextNumber = $_REQUEST['TextNumber'];}
else{$TextNumber = "12";}
if(isset($_GET['AnyText'])){$AnyText = $_GET['AnyText'];}
elseif(isset($_POST['AnyText'])){$AnyText = $_POST['AnyText'];}
elseif(isset($_REQUEST['AnyText'])){$AnyText = $_REQUEST['AnyText'];}
else{$AnyText = "Table";}
$text = $TextNumber;
// Add some shadow to the text - this was workin
imagettftext($im, 20, 0, 11, 41, $grey, $font, $AnyText);
// Add the text - this was workin
imagettftext($im, 20, 0, 10, 40, $red, $font, $AnyText);
// Add some shadow to the Number - this was workin
imagettftext($im, 20, 0, 11, 81, $grey, $font, $TextNumber);
// Add the Number - this was workin
imagettftext($im, 20, 0, 10, 80, $black, $font, $TextNumber);
imagegif($im); // this was png and was workin
imagedestroy($im);
?>
function LoadGif ($imgname)
{
$im = @imagecreatefromgif ($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetruecolor (150, 30); /* Create a blank image */
$bgc = imagecolorallocate ($im, 255, 255, 255);
$tc = imagecolorallocate ($im, 0, 0, 0);
imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
I dropped your sample code onto my server, removed the leading "/" from the filename of the source GIF, made a 110x110 source gif and placed it in the same directory as the script, and the code worked perfectly. Are you sure that the path to the source GIF is correct? Using an absolute file reference like that might mean it's looking for "TemplateButton.gif" at the root of your hard drive as opposed to the DOCUMENT_ROOT of your website.
Also, out of curiosity, are you using the Entropy PHP build, the Server Logistics build, or your own?
You can learn alot about what GD support you have by looking at the output of <?php gd_info();?>
If your version doesn't support GIF, you'll need to either recompile PHP with newer versions of GD/PHP or use one of the easy installers that will "replace" the standard PHP with a more feature-packed version. My favorite is the Entropy PHP build [entropy.ch]. I recommend it and so does Apple [developer.apple.com]. (That Apple link also describes how to "do it yourself.")
There's also the "hasn't been updated for a year, but has some extra cool stuff" Server Logistics PHP build [serverlogistics.net] that I've used and like.
I've heard of, but never tried the relative newcomer MAMP PHP build [mamp.info].