I have this script which creates a thumbnail from a large picture.
I am trying to add text over it but with little success.
I have got the overlay script from the following, which works on it's own but not with the first part of my script.
Please tell me what I am missing.
What is the function of $bg?
Keith
I am trying to add text over it but with little success.
Code:
<?php
$img_name=$_GET['imnam'];
$max_width = 150; // maximum x aperture in pixels
$max_height = 150; // maximum y aperture in pixels
$size=GetImageSize($img_name);
$width_ratio = ($size[0] / $max_width);
$height_ratio = ($size[1] / $max_height);
if($width_ratio >=$height_ratio)
{
$ratio = $width_ratio;
}
else
{
$ratio = $height_ratio;
}
$new_width = ($size[0] / $ratio);
$new_height = ($size[1] / $ratio);
Header("Content-Type: image/jpeg");
$src_img = ImageCreateFromJPEG($img_name);
$thumb = ImageCreateTrueColor($new_width,$new_height);
ImageCopyResampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);
ImageJPEG($thumb);
$textcolor = imagecolorallocate($thumb, 255, 255, 255);
imagestring($thumb, 5, 0, 0, "AD", $textcolor);
ImageDestroy($src_img);
ImageDestroy($thumb);
?>
Code:
<?php
// create a 100*30 image
$im = imagecreatetruecolor(100, 30);
// white background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
// write the string at the top left
imagestring($im, 5, 0, 0, "Hello world!", $textcolor);
// output the image
header("Content-type: image/jpeg");
imagejpeg($im);
?>
What is the function of $bg?
Keith