Dodger42
asked on
PNG problem after imagecreatefrompng
Hey all,
I create a png image using imagecreatefrompng. On the system on which the output image is saved, I can doubleclick and view it no problem. But trying to grab it via a browser (IE, Firefox, Opera all tested, and from different computers) it simply displays garbage (similar to when the header or application associated has failed). I put another PNG image in the directory (created also using imagecreatefrompng) and it can be viewed no problem.
You can view the images here:
www.lomac-stats.com/IA/
click on the sig image on the right.
Any assistance would be greatly appreciated.
I create a png image using imagecreatefrompng. On the system on which the output image is saved, I can doubleclick and view it no problem. But trying to grab it via a browser (IE, Firefox, Opera all tested, and from different computers) it simply displays garbage (similar to when the header or application associated has failed). I put another PNG image in the directory (created also using imagecreatefrompng) and it can be viewed no problem.
You can view the images here:
www.lomac-stats.com/IA/
click on the sig image on the right.
Any assistance would be greatly appreciated.
ASKER
When I run a signature generator, it works fine:
http://www.lomac-stats.com/sigs/smallsig.php?id=42SF-Dodger
That image is generated in more or less the same way except it is sent to the browser direct without saving it.
http://www.lomac-stats.com/sigs/smallsig.php?id=42SF-Dodger
That image is generated in more or less the same way except it is sent to the browser direct without saving it.
$dst_img vs $dest_img in your second code.
This is the response I am getting from your main page for the image.
HTTP/1.1 200 OK
Connection: close
Proxy-Connection: close
Date: Mon, 15 May 2006 08:22:31 GMT
Content-Type: text/html
Server: Apache
X-Powered-By: PHP/5.1.2
NOTE: Content type = text/html
Do you have a script which is running when the URL contains ../sigs/?
A script which takes the bit at the end and runs it as a parameter?
If so, can you show us the code for that?
Alternatively have you configured png files in the sigs directory to NOT be png files?
HTTP/1.1 200 OK
Connection: close
Proxy-Connection: close
Date: Mon, 15 May 2006 08:22:31 GMT
Content-Type: text/html
Server: Apache
X-Powered-By: PHP/5.1.2
NOTE: Content type = text/html
Do you have a script which is running when the URL contains ../sigs/?
A script which takes the bit at the end and runs it as a parameter?
If so, can you show us the code for that?
Alternatively have you configured png files in the sigs directory to NOT be png files?
ASKER
This is the first script which queries the DB and gets a list of names to loop whilst creating the sigs.
<?php
include_once("allfunctions .php");
include_once("../include/d b_connect. php");
$sql = "SELECT pilot_callsign FROM rankings";
$result = mysql_query($sql);
if(!$result)
{
echo "Sorry database is being worked on";
die;
}
$numberOfRows = mysql_num_rows($result);
if(numberOfRows == '0')
{
echo "No matches";
}
if($numberOfRows>0) {$i=0;}
while ($i<$numberOfRows)
{
$pilot_callsign = MYSQL_RESULT($result,$i,"p ilot_calls ign");
siggen($pilot_callsign,'IA ');
$i++;
}
echo "Signatures generated: ".$numberOfRows;
?>
It calls teh function siggen with parameter $pilot_callsign and a statically assigned var.
the siggen function is within the function code and is as follows:
<?php
function siggen($pilot_callsign, $server){
$debug = false;
if ($debug == "true") {}
//include('../include/db_c onnect.php ');
if ($debug == "true") {echo $pilot_callsign."<br>";}
$filenamedirty = preg_replace('/[^a-z0-9]/i ','',$pilo t_callsign );
//$filename = md5($pilot_callsign);
$filename = $filenamedirty.".png";
if ($debug == "true") {echo $filename;}
$image1 = "minisigback.png";
$image2 = "bottom_sign.png";
$user = "xxxxxxx";
$passwd = "xxxxxxx";
$server = "xxxxxxx";
$db = 'xxxxxxx';
$connect = mysql_connect($server, $user, $passwd);
mysql_select_db($db);
$sql = "SELECT * FROM rankings WHERE pilot_callsign = '$pilot_callsign'";
$result = mysql_query($sql);
$numberOfRows = mysql_num_rows($result);
if ($numberOfRows == '0') { die('No results found');}
//$row = mysql_fetch_assoc($result) ;
$i=0;
$a2a_kills = MYSQL_RESULT($result,$i,"a 2a_kills") ;
$a2g_kills = MYSQL_RESULT($result,$i,"a 2g_kills") ;
$ship_kills = MYSQL_RESULT($result,$i,"s hip_kills" );
mysql_close($connect);
$dest_x = 498;
$dest_y = 30;
$brush_width = 4;
$pilot_callsign_font_size = 20;
$font_size = 12;
$text_from_left = 8;
$text_from_top = 5;
$font_file = "bombard.TTF";
if ($debug == "true") {echo "break_1"."<br>";}
do
{
$quote = $array[rand(1,sizeof($arra y))];
$box = imagettfbbox($font_size, 0, $font_file, $quote);
}while($box[4] > ($dest_x-(2*$brush_width)- $text_from _left = 8));
if ($debug == "true") {echo "break_1a"."<br>";}
if(!$dest_img = @imagecreatefrompng("minis igback.png "))
exit;
if(!$bottom_img = @imagecreatefrompng("botto m_sign.png "))
exit;
/*
*/
if ($debug == "true") {echo "break_3"."<br>";}
// make some colors
$white = imagecolorallocate($dest_i mg, 255, 255, 255);
$black = imagecolorallocate($dest_i mg, 0, 0, 0);
$red = imagecolorallocate($dest_i mg, 255, 0, 0);
imagettftext($dest_img, 20, 0, 16, 24, $black, $font_file, $pilot_callsign);
imagettftext($dest_img, $font_size, 0, 310, 20, $red, $font_file, $a2a_kills);
imagettftext($dest_img, $font_size, 0, 390, 20, $red, $font_file, $a2g_kills);
imagettftext($dest_img, $font_size, 0, 475, 20, $red, $font_file, $ship_kills);
//header("Content-type: image/png");
imagepng($dest_img, $filename);
imagedestroy($dest_img);
imagedestroy($bottom_img);
}
?>
<?php
include_once("allfunctions
include_once("../include/d
$sql = "SELECT pilot_callsign FROM rankings";
$result = mysql_query($sql);
if(!$result)
{
echo "Sorry database is being worked on";
die;
}
$numberOfRows = mysql_num_rows($result);
if(numberOfRows == '0')
{
echo "No matches";
}
if($numberOfRows>0) {$i=0;}
while ($i<$numberOfRows)
{
$pilot_callsign = MYSQL_RESULT($result,$i,"p
siggen($pilot_callsign,'IA
$i++;
}
echo "Signatures generated: ".$numberOfRows;
?>
It calls teh function siggen with parameter $pilot_callsign and a statically assigned var.
the siggen function is within the function code and is as follows:
<?php
function siggen($pilot_callsign, $server){
$debug = false;
if ($debug == "true") {}
//include('../include/db_c
if ($debug == "true") {echo $pilot_callsign."<br>";}
$filenamedirty = preg_replace('/[^a-z0-9]/i
//$filename = md5($pilot_callsign);
$filename = $filenamedirty.".png";
if ($debug == "true") {echo $filename;}
$image1 = "minisigback.png";
$image2 = "bottom_sign.png";
$user = "xxxxxxx";
$passwd = "xxxxxxx";
$server = "xxxxxxx";
$db = 'xxxxxxx';
$connect = mysql_connect($server, $user, $passwd);
mysql_select_db($db);
$sql = "SELECT * FROM rankings WHERE pilot_callsign = '$pilot_callsign'";
$result = mysql_query($sql);
$numberOfRows = mysql_num_rows($result);
if ($numberOfRows == '0') { die('No results found');}
//$row = mysql_fetch_assoc($result)
$i=0;
$a2a_kills = MYSQL_RESULT($result,$i,"a
$a2g_kills = MYSQL_RESULT($result,$i,"a
$ship_kills = MYSQL_RESULT($result,$i,"s
mysql_close($connect);
$dest_x = 498;
$dest_y = 30;
$brush_width = 4;
$pilot_callsign_font_size = 20;
$font_size = 12;
$text_from_left = 8;
$text_from_top = 5;
$font_file = "bombard.TTF";
if ($debug == "true") {echo "break_1"."<br>";}
do
{
$quote = $array[rand(1,sizeof($arra
$box = imagettfbbox($font_size, 0, $font_file, $quote);
}while($box[4] > ($dest_x-(2*$brush_width)-
if ($debug == "true") {echo "break_1a"."<br>";}
if(!$dest_img = @imagecreatefrompng("minis
exit;
if(!$bottom_img = @imagecreatefrompng("botto
exit;
/*
*/
if ($debug == "true") {echo "break_3"."<br>";}
// make some colors
$white = imagecolorallocate($dest_i
$black = imagecolorallocate($dest_i
$red = imagecolorallocate($dest_i
imagettftext($dest_img, 20, 0, 16, 24, $black, $font_file, $pilot_callsign);
imagettftext($dest_img, $font_size, 0, 310, 20, $red, $font_file, $a2a_kills);
imagettftext($dest_img, $font_size, 0, 390, 20, $red, $font_file, $a2g_kills);
imagettftext($dest_img, $font_size, 0, 475, 20, $red, $font_file, $ship_kills);
//header("Content-type: image/png");
imagepng($dest_img, $filename);
imagedestroy($dest_img);
imagedestroy($bottom_img);
}
?>
You commented out the header().
THIS MUST BE UNCOMMENTED!!!!
THIS MUST BE UNCOMMENTED!!!!
ASKER
What makes it very odd is this:
1. I can open the siganture PNG files through windows explorer on the server itself. This made me suspect something in the httpd.conf file or the headers.
2. I have other PNG files sitting in the same folder and they open fine (even some which were created with PHP). So that would suggest the httpd.conf is fine (and I just checked that out - seems not to be a problem).
?? puzzling
1. I can open the siganture PNG files through windows explorer on the server itself. This made me suspect something in the httpd.conf file or the headers.
2. I have other PNG files sitting in the same folder and they open fine (even some which were created with PHP). So that would suggest the httpd.conf is fine (and I just checked that out - seems not to be a problem).
?? puzzling
ASKER
In regards to uncommenting, that is only if I want to send the file to the browser right. That siggen function saves the file. "imagepng($dest_img, $filename);" (and does so successfully).
Oh yeah. I didn't see you were saving the images.
What happens if you temporarily enable directory searching on the sigs folder and then use a browser to simply pull the files up?
What happens if you temporarily enable directory searching on the sigs folder and then use a browser to simply pull the files up?
ASKER
I tried with that uncommented and you just get a bunch of header errors. I will comment it out again.
still even if that was the problem, you wouldnt expect it would be possible to open the png on the server itself without issue.
still even if that was the problem, you wouldnt expect it would be possible to open the png on the server itself without issue.
WHAT ERRORS?
Can you manually create a quick page to allow access to the images as they are?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wow... a stranger development. If I open up a web browser on the server itself, the images are displayed perfectly.
Bizarre!!
Bizarre!!
ASKER
Ok getting close. Copying the PNG out of the sigs folder into / folder and I can view them fine. Must be something I am missing in the httpd.conf.
Apache can play all sorts of tricks. Some of them are on the users! Some of them are very silly and very very difficult to track down.
ASKER
I know a while back I set a config in apache to open png files within the /sigs directory using php. But that config is now gone (dont recall deleting it from httpd.conf). I just checked the config, there is no application config for png files in there, so I restarted apache (in case the running process had that old config), but no change.
Is there another config file I should check out? I took a look at the mime.types. Nothing in there.
Is there another config file I should check out? I took a look at the mime.types. Nothing in there.
ASKER
In the apache error log, lots of these:
[Mon May 15 19:47:27 2006] [error] [client xxx.xxx.xxx.xxx] File does not exist: DriveLetter:/www/favicon.i co, referer: http://www.lomac-stats.com/sigs/42SFDodger.png
I have no idea what would be looking for that.
[Mon May 15 19:47:27 2006] [error] [client xxx.xxx.xxx.xxx] File does not exist: DriveLetter:/www/favicon.i
I have no idea what would be looking for that.
ASKER
Well I fixed it by moving the sigs directory to a new directory called /sig. There must be something in a config file, but I just cant find it.
favicon.ico is a tiny image to be used in shortcuts/favourites and the URL image.
I think IE first used this and others followed.
http://favicon.com/
I think IE first used this and others followed.
http://favicon.com/
ASKER
Well although the answer was not really correct, RQuading helped me find the answer. I still havent determined the exact cause, but I know there is a buggy config for the sig dir.
ASKER
<?php
$var = $_REQUEST[id];
if (!$var)
{
$dst_image = "42SF-Dodger.png";
}
else
{
$dst_image = $var.".png";
}
//echo $dst_image;
header("Content-type: image/png");
imagepng($dest_img);
imagedestroy($dest_img);
imagedestroy($bottom_img);
?>
But it fails with an image error.