Dynamic Images (GD) - Some loading, Some not....
Posted: Tue Oct 01, 2002 6:26 pm
I am creating on the fly images with PHP and GD. I am using the following code to do this. When the calling page is loaded, some of the images do not display. They are replaced with the broken image placeholder. However, if I right click the image and select Show Image it is displayed. (Internet Explorer 6) Any help would be greatly appreciated.
Code: Select all
<?php
//error_reporting(E_NOTICE);
if ($image) {
$imgfile=urldecode($image);
$label=urldecode($label);
if (is_file($imgfile)) {
/*
Get Size of input file and declare/assign variables for them
*/
$sizearray = GetImageSize($imgfile);
$src_width = $sizearrayї0];
$src_height = $sizearrayї1];
/*
Create our temporary image in porportion to the original
Create 2 times as large as $imgfile to allow for better results with TTF (true type font)
*/
$image_temp = ImageCreateTrueColor($src_width*2,$src_height*2);
/*
Allocate our colors of course
*/
$black = ImageColorAllocate($image_temp,0,0,0);
$white = ImageColorAllocate($image_temp,255,255,255);
/*
Fill our background with white for transparency
*/
ImageFill($image_temp,0,0,$white);
/*
Render the text onto the image:
Done 3 times to fatten up the text
Notice the offset in each render.
*/
ImageTTFText($image_temp,20,0,42,30,$black,realpath("tahoma.ttf"),$label ."\r");
/*
Create an image to resize the text/transparency layer to
*/
$img_resampled = ImageCreateTrueColor($src_width,$src_height);
/*
Set the transparency
*/
ImageColorTransparent($img_resampled,$white);
/*
Resize the text/transparency image ($image_temp)
*/
ImageCopyResampled($img_resampled,$image_temp,0,0,0,0,$src_width,$src_height,ImageSX($image_temp),ImageSY($image_temp));
/*
Create our final canvas from the background file provided
*/
ImageDestroy($image_temp);
$image_final = ImageCreateFromJPEG($imgfile);
/*
Merge the layers
*/
ImageCopyMerge($image_final,$img_resampled,0,0,0,0,$src_width,$src_height,70);//,ImageSX($image_temp),ImageSY($image_temp));
/*
send our header and image to the browser
*/
header("Content: image/png");
ImagePNG($image_final);
ImageDestroy($image_final);
ImageDestroy($image_resampled);
} else {
header("Content: text/html");
die ("Image File not found ($image)");
}
} else {
die ("Syntax: createimage.php?\$imagestr&\$label");
}
?>