Forum Moderators: coopster
However, my php script that uses imagecopymerge to add two images together does not seem to work at all. In fact, all I get is a blank page. My html page does not give me the two images combined at all. I get a blank page or I get an error depending on the browser I test with. On IE 6SP2, I get a blank page with nothing. In Firefox 1.0.2 I get the following error: The image “http://localhost/Images/BuildImage.php” cannot be displayed, because it contains errors.
My code in the PHP script is listed below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Generate Image</title>
</head>
<body>
<?php
// BuildImage.php Image Generating Server-Side Application
header("Content-type: image/png");
// load the images
$baseimage = imagecreatefrompng("/AppImages/BaseImage.png");
$line1 = imagecreatefrompng("/AppImages/line1.png");
// merge the two images together at specific points
imagecopymerge($baseimage, $line1, 330, 382, 0, 0, 220, 53, 100);
// Display the merged images on a browswer
imagepng($baseimage);
// Create a local png file of the merged images
imagepng("/AppImages/Output/newimage.png");
// clear memory
imagedestroy($baseimage);
imagedestroy($line1);
?>
</body>
</html>
The code is seemingly simple and matches that of many examples I have found on the web and in books. It does not seem to work however. I am having trouble troubleshooting it for various reasons: 1) I am not 100% certain that there is not some webserver or php.ini configuration issue still at hand even though my phpinfo returns good news 2) I troubleshot the Firefox error down to every line of code being taken out and the one line of code causing the problem is this: header("Content-type: image/png"); which makes no sense to me 3) Even with this line taken out, my code that tells PHP GD to output to a local file on the web server should work and it does not. 4) I am a PHP novice.
In fact, the only thing that appears to be happening is the script executes and returns me nothing at all.
Any suggestions or ideas from anyone would be greatly appreciated. I can supply any additional information needed. I have spent hours upon hours trying to figure this out and need some help.
Many thanks in advance...
$baseimage = imagecreatefrompng("/AppImages/BaseImage.png");
$line1 = imagecreatefrompng("/AppImages/line1.png");
These functions' arguments are real paths on the filesystem, not relative to your web site. I'm not sure you are looking in the right places for your images. Where on the filesystem are these images located? If you're using windows, shouldn't it be c:\somewhere\htdocs\AppImages\filename.png?
Just a thought...