I have a script I wrote to create button links with GD. It works great on any graphic except one that has a gradient in it. I have tried making the base image be a .png and a .gif and I have also tried outputing a .gif and a .png and every time it works with a normal image but as soon as I have a gradient in the source image it does not work right. Here is the php code I am using, it is just a function that loads the source image and then saves the finished graphic to the server:
function make_buttons($style_button,$button_name,$image_name_raw) {
global $main_dir;
global $domain_path;
// This is what to expect out of $button_options:
// button,button_over,font,font-size,font_color,font_color_over
$button_options = explode(",", $style_button);
// Find what the name of the image will be
$image_name = $domain_path."/buttons/".$image_name_raw.".gif";
$image_name_over = $domain_path."/buttons/".$image_name_raw."_over.gif";
// Get our colors for font_color
sscanf($button_options[4], "%2x%2x%2x", $red1, $green1, $blue1);
// Get our colors for font_color_over
sscanf($button_options[5], "%2x%2x%2x", $red2, $green2, $blue2);
// Get the path to the template image
$template_image = $main_dir."/pics/".$button_options[0];
$template_image_over = $main_dir."/pics/".$button_options[1];
// Get the fontsize and the font to use
$pointsize = $button_options[3];
$fontfile = $main_dir."/fonts/".$button_options[2];
// Find the size of the image
@$size = GetImageSize ($template_image);
$i_width = $size[0];
$i_height = $size[1];
// Find the size of the text
$string_size = ImageFtBbox($pointsize, 0, $fontfile, $button_name, array("linespacing" => 1));
$s_width = $string_size[4];
$s_height = $string_size[5];
// Lets get the math done
$free_width = $i_width - $s_width;
$from_left = $free_width / 2;
$free_height = $i_height - $s_height;
$from_top = $free_height / 2;
// *** Start making the first image *** //
$im = ImageCreateFromGIF($template_image);
$font_color = imagecolorallocate ($im, $red1, $green1, $blue1);
//ImageFtText($im, $pointsize, 0, $from_left, $from_top, $font_color, $fontfile, $button_name, array("linespacing" => 1));
ImageTTFText($im, $pointsize, 0, $from_left, $from_top, $font_color, $fontfile, $button_name);
imageGIF($im, $image_name);
ImageDestroy ($im);
// *** Start making the second image *** //
$im_over = ImageCreateFromGIF($template_image_over);
$font_color_over = imagecolorallocate ($im_over, $red2, $green2, $blue2);
ImageFtText($im_over, $pointsize, 0, $from_left, $from_top, $font_color_over, $fontfile, $button_name, array("linespacing" => 1));
imageGIF($im_over, $image_name_over);
ImageDestroy ($im_over);
}
And a link to 2 sites that have buttons created by this script:
The Working Site:
www.addeasy.net
And the one I am having problems with:
demo.addeasy.net
Both sites are using the same fontfile and the same font colors and everything, it looks like it used a system font and the color from the gradient where the text should be the same as the www.addeasy.net
Also a link to the phpinfo page:
http://dev.worldconnx.net/phpinfo.php
Also if you want to see the source graphics here they are
One for [url]www.addeasy.net:[/url]
http://dev.worldconnx.net/pics/style3.gif
One for demo.addeasy.net
http://dev.worldconnx.net/pics/style6.gif