I have this code that loads a png file. and inserts text using a specified font.
My only problem is that the text is always yellow, regardless of how i try to set it.
Anybody have any ideas?
thanks!
My only problem is that the text is always yellow, regardless of how i try to set it.
Anybody have any ideas?
PHP Code:
$im_size = getimagesize($img);
$image_width = $im_size[0];
$image_height = $im_size[1];
$im = imagecreatetruecolor($image_width, $image_height);
$im2 = imagecreatefromPNG($img);
imagecopy($im, $im2, 0, 0, 0, 0, $image_width, $image_height);
imagedestroy($im2);
$white = imagecolorallocate($im, 0, 0, 0);
$black = Imagecolorallocate($im, 255, 255, 255);
// Calculate text position
$bounding_box = imagettfbbox($font_size, 0, $font_file, $text);
$horz_pos = $image_width - $bounding_box[2] - $bounding_box[0] - 25;
$vert_pos = $image_height - 25;
// Write the text to the image, using the drop shadow effect
imagettftext($im, $font_size, $angle, $horz_pos, $vert_pos, $black, $font_file, $text);
$horz_pos -= 1;
$vert_pos -= 1;
imagettftext($im, $font_size, $angle, $horz_pos, $vert_pos, $black, $font_file, $text);
$horz_pos -= 1;
$vert_pos -= 1;
imagettftext($im, $font_size, $angle, $horz_pos, $vert_pos, $white, $font_file, $text);
ImageInterlace($im, true);
// Create and then destroy the image (discussed in steps 5 and 6)
header("Content-type: image/png");
imagePNG($im);
imagedestroy($im);
?>