Hi everyone,
I’m trying to write a script that automates the task of creating button sets for a website.
Basically, I create three image files: the left side of the button, the right side, and a section of middle. The function (which takes the ‘label text’ and ‘output file’ as arguments) should judge the amount of middle section needed for the text, then ‘glue’ the pieces together to create an appropriate size button image. Then it should paste the label on top, and save to a file.
I have some pseudo code, but I’m not sure what image function should be used to glue an image onto the right side of an existing image…
[code=php]
function create_button($text, $filename)
{
$lc_image = @imagecreatefromgif(‘filename1.gif’); // import the left cap
$mid_image = @imagecreatefromgif(‘filename2.gif’); //import the right cap
$rc_image = @imagecreatefromgif(‘filename3.gif’); // import the middle chunk
$text_len = strlen($text); //take the var $text and figure out how long it is
//create a variable for the final output image, and insert the left cap into it
$final_im = $lc_image;
for($i = 1, $i < $text_len, $i++)
{
$final_im .= $mid_image; // paste copies of the center section onto the main image untill it’s wide enough to fit the text
}
$final_im .= $rc_image; // paste the right cap on the end
// $final_im should now contain a complete blank button that’s the right size….
// now take $text and paste it on top in the center of the button
$final_im = imagestring($final_im, 3, 5, 3, $text, ‘#ffffff’);
$result = imagegif($final_im, $filename); //save the final image to a gif file
}