Forum Moderators: coopster

Message Too Old, No Replies

imagecopymerge on Apache on WinXP Issue

Trouble getting PHP image generation to work

         

redundant not

5:15 am on Apr 21, 2005 (gmt 0)

10+ Year Member



I am running Apache 1.3.33 for Win32 on WinXP with SP2. I have PHP Version 4.3.10 as well with the GD2 extension configured and loaded. If I run a PHPinfo script from a web page it returns all good news about everything (see output below):
-------------------------------------------------------
Build Date Dec 14 2004 17:46:48
Server API CGI/FastCGI
Virtual Directory Support enabled
Configuration File (php.ini) Path c:\php\php.ini
PHP API 20020918
PHP Extension 20020429
Zend Extension 20021010
Debug Build no
Thread Safety enabled
Registered PHP Streams php, http, ftp, compress.zlib, compress.bzip2
-------------------------------------------------------
GD Support enabled
GD Version bundled (2.0.28 compatible)
FreeType Support enabled
FreeType Linkage with freetype
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
-------------------------------------------------------

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...

jusdrum

5:46 pm on Apr 22, 2005 (gmt 0)

10+ Year Member



$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...

coopster

2:14 am on Apr 27, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, redundant not.

Any news on your issue yet?

redundant not

12:09 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



The local windows file system as the path for imagecopymerge and imagecreatefrompng are correct. This at least gets me some output on my browser. But it is all garbled text. I wonder if my html meta tag for text/html is causing a mismatch with my PHP tag for output as image?
I am going to test this theory now. I will update again with my results.

redundant not

12:39 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



Nope same garbage appears on the browser instead of my images. The other thing is that my output to a file is not working either. A file is not even made. Not sure what is going on here. This stuff seems to work for millions of other websites.

coopster

2:15 am on Apr 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Make sure you have the correct authority to write the file to whatever directory you are trying to dump it to. I'd start there first, too. Trying to get browsers, especially IE, to understand what the document is and how to open it can be a royal pain. Dump the image to a file first, then work with it. Check the permissions of the folder you are trying to write the file to, make sure you open it up so you can get the thing out there first.