the code for making different buttons (with different texts) from a flat button template is as follow:
Code: Select all
<?php
$button_text ='love';
$im= imagecreatefrompng('blue-button.png');
if (!$im)
{
echo 'couldn\'t create image from file';
}
$image_width = imagesx($im);
$image_height = imagesy($im);
$image_width_wo_marign = $image_width - (2 * 6);
$image_height_wo_marign = $image_height - (2 * 6);
$fontsize = 33;
putenv('GDFONTPATH=D:\win.xp\fonts');
$fontname = 'arial';
$green = imagecolorallocate($im,22,255,8);
do
{
$fontsize--;
$bbox = imageTTFbbox($fontsize,0,$fontname,$button_text);
$text_lef = $bbox[0];
$text_right = $bbox[2];
$text_width = $text_right - $text_lef;
$text_height = abs($bbox[7] - $bbox[1]);
}
while ($fontsize>8 && ($text_width > $image_width_wo_marign ||
$text_height > $image_height_wo_marign));
if ( $text_width> $image_width_wo_marign ||
$text_height >$image_height_wo_marign)
{
echo "Text cannot fit on the button";
}
else
{
$text_x = $image_width/2.0 - $text_width/2.0;
$text_y = $image_height/2.0 - $text_height/2.0;
if ($text_left<0)
$text_x -=$text_left;
$above_line_text = abs($bbox[7]);
$text_y += $above_line_text;
$text_y+=2;
$red = imagecolorallocate($im,230,0,0);
//imageTTFtext($im,$fontsize,$angle,$text_x,$text_y,$red,$fontname,$button_text);
imageTTFtext($im,12,0,10,25,$green,$fontname,'L');
//header("Content-type = image/png");
imagepng($im);
imagedestroy($im);
}
?>what I didn't understad is from after the do loop
Code: Select all
$text_x = $image_width/2.0 - $text_width/2.0;
$text_y = $image_height/2.0 - $text_height/2.0;
if ($text_left<0)
$text_x -=$text_left;
$above_line_text = abs($bbox[7]);
$text_y += $above_line_text;
$text_y+=2;now if someone know what these caculations do in depth please explain them for me?
sincerely
the_one2003a
feyd | please post php in
Code: Select all
tags.[/color]