Hi all,
I'm new to PHP, and was attracted to it because of the ability to create images "on-the-fly". I've written one other PHP script that uses a "pretty" background image then draws a chart over it. That works great.
Now, I'm trying to create/build an image using php. I start with a base image, and then add png images of the same size with transparent areas. The idea is to build an object using selected pieces.
I'm using imagecopymerge to combine the images, but when I view the "image" directly in the browser, FF. it displays:
The image “http://www.sloanthra...6&sz=3&f=2&w=1” cannot be displayed, because it contains errors.
Clicking the link will call the file with options and you can see the error I'm seeing in Firefox:
GetImg.php?b=2&tb=8&bb=2&sk=6&sz=3&f=2&w=1
To see the full code:
http://www.sloanthra...code/GetImg.txt
Thanks for any help!!
Sloan
Trouble layering several PNG images to send to brower
Started by SloanThrasher, Jun 28 2010 11:41 AM
9 replies to this topic
#1
Posted 28 June 2010 - 11:41 AM
|
|
|
#2
Posted 28 June 2010 - 02:15 PM
I would start removing the comments that are designed for debugging purposes. ie:
If that doesn't make the error more apparent, look in your error_log file, there should be something in there regarding your issue. If that fails, rewrite the code in small portions so you can know where the issue is.
if (!$imJig) {
# echo "Error loading Image: ".$image;
# exit;
}
If that doesn't make the error more apparent, look in your error_log file, there should be something in there regarding your issue. If that fails, rewrite the code in small portions so you can know where the issue is.
#3
Posted 28 June 2010 - 05:02 PM
Thanks John,
I trimmed it down to just a few lines, and it gives me an error:
Parse error: syntax error, unexpected T_VARIABLE in M:\Chameleon\LocalUser\sloanthrasher\WebSites\SloanThrasher.com\LeenaLures\PHP Code\GetImg2.php on line 44
Here's lines 42 - 44:
I looked for the error_log file, but have no clue where it might be. I'm on a shared server, so I don't have access to the PHP folder and such. Any ideas where I might find it?
Sloan
PS
Sorry for the ultra newbie questions.
I trimmed it down to just a few lines, and it gives me an error:
Parse error: syntax error, unexpected T_VARIABLE in M:\Chameleon\LocalUser\sloanthrasher\WebSites\SloanThrasher.com\LeenaLures\PHP Code\GetImg2.php on line 44
Here's lines 42 - 44:
$BackgroundImg = "background_02.png" $tmp_image = $basedir.$SizeFolder.$BackgroundImg; $imBg = imagecreatefrompng($tmp_image);
I looked for the error_log file, but have no clue where it might be. I'm on a shared server, so I don't have access to the PHP folder and such. Any ideas where I might find it?
Sloan
PS
Sorry for the ultra newbie questions.
#5
Posted 28 June 2010 - 05:37 PM
Thanks! I knew there was something obvious...
#6
Posted 28 June 2010 - 06:45 PM
Ok, I've trimmed to code down to this:
Now I'm getting this error:
The image “http://www.sloanthra...&f=2&w=1” cannot be displayed, because it contains errors.
I added some code to test if the path and file were correct (file_exists()), and it was able to find the image. I can also display the image by direct reference in the browser.
Any ideas?
Thanks!
<?php
$basedir="/LeenaLures/images/Custom Lure pics/LureParts/";
$SizeFolder = "1024x768/";
$BackgroundImg = "background_02.png";
$tmp_image = $basedir.$SizeFolder.$BackgroundImg;
if (file_exists($tmp_image)) {
header("Content-Type: text/txt");
header("File-Name:test.txt");
echo "File Not Found".$tmp_image;
} else {
$imBg = imagecreatefrompng($tmp_image);
header("Content-Type: image/png");
header("Last-Modified: $last_modified");
header("File-Name:test.png");
imagepng($imBg);
imagedestroy($imBg);
}
?>
Now I'm getting this error:
The image “http://www.sloanthra...&f=2&w=1” cannot be displayed, because it contains errors.
I added some code to test if the path and file were correct (file_exists()), and it was able to find the image. I can also display the image by direct reference in the browser.
Any ideas?
Thanks!
#7
Posted 28 June 2010 - 07:25 PM
A handy debugging method when working with GD is commenting out each of the header() and imagepng()/imagedestroy() functions and it will allow to output the error in plaintext as otherwise it would just give you a useless error. When you resolve all errors the image should work after.
EDIT: Did you mean for it to be this?
EDIT: Did you mean for it to be this?
if ([b]![/b]file_exists($tmp_image)) {
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#8
Posted 28 June 2010 - 08:16 PM
Thanks for all the help so far!!
I've finally gotten it to run without an error, but the imagecopymerge doesn't seem to work. I load the background image, then load another image. The second image is a simple object surrounded with fully transparent pixels. The image displayed is of the background image only -- the 2nd image is nowhere to be seen. Am I missing something with the imagecopymerge function?
By the way, both images are the same size, compression, etc.
Here's the current code:
I've finally gotten it to run without an error, but the imagecopymerge doesn't seem to work. I load the background image, then load another image. The second image is a simple object surrounded with fully transparent pixels. The image displayed is of the background image only -- the 2nd image is nowhere to be seen. Am I missing something with the imagecopymerge function?
By the way, both images are the same size, compression, etc.
Here's the current code:
<?php
#$basedir="/LeenaLures/images/Custom Lure pics/LureParts/";
$basedir="../images/Custom Lure pics/LureParts/";
$SizeFolder = "1024x768/";
$BackgroundImg = "background_03.png";
$tmp_image = $basedir.$SizeFolder.$BackgroundImg;
if (file_exists($tmp_image)) {
if (1==1) {
$imBg = imagecreatefrompng($tmp_image);
$ImgX = imagesx($imBg);
$Imgy = imagesy($imBg);
#$ImgX = 1024;
#$ImgY = 768;
$tmp_image = $basedir.$SizeFolder."jig.png";
$imJig = imagecreatefrompng($tmp_image);
imagecopymerge($imBg, $imJig, 0, 0, 0, 0, $ImgX, $ImgY,100);
header("Content-Type: image/png");
header("Last-Modified: $last_modified");
header("File-Name:test.png");
imagepng($imBg);
imagedestroy($imBg);
imagedestroy($imJig);
} else {
header("Content-Type: text/txt");
header("File-Name:test.txt");
echo "File Found: ".$tmp_image;
}
} else {
header("Content-Type: text/txt");
header("File-Name:test.txt");
echo "File Not Found: ".$tmp_image;
}
?>
Any help will be gratefully received!!
#9
Posted 28 June 2010 - 09:29 PM
Hmm.. Try replacing the imagecopymerge() function with imagecopy(), the parameters are the same except remove the last one (100), does that work? I read in the documentation that imagecopymerge does not support alpha channels on pngs, maybe it's just that.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#10
Posted 29 June 2010 - 10:26 AM
I tried that, but still no joy. The image that is displayed is just the first image (background), without the second image. If I swap images, then the other image is displayed without the background image. Am I using the wrong function? Is there another function that will combine the two images, respecting the transparency of the second image?


Sign In
Create Account

Back to top









