Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not Overlaying text

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I have this script which creates a thumbnail from a large picture.
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);
?>
I have got the overlay script from the following, which works on it's own but not with the first part of my script.
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);
?>
Please tell me what I am missing.
What is the function of $bg?

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top