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.
Dodger42Asked:
Who is Participating?
 
Richard QuadlingSenior Software DeveloperCommented:
Do you have ANY configs set in the server? ANY at all?
0
 
Dodger42Author Commented:
I thought it might be something to do with headers being screwed, so I tried creating a viewer as follows:

<?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.
0
 
Dodger42Author Commented:
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.

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Richard QuadlingSenior Software DeveloperCommented:
$dst_img vs $dest_img in your second code.
0
 
Richard QuadlingSenior Software DeveloperCommented:
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?
0
 
Dodger42Author Commented:
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/db_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,"pilot_callsign");
      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_connect.php');
if ($debug == "true") {echo $pilot_callsign."<br>";}

$filenamedirty = preg_replace('/[^a-z0-9]/i','',$pilot_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,"a2a_kills");
      $a2g_kills = MYSQL_RESULT($result,$i,"a2g_kills");
      $ship_kills = MYSQL_RESULT($result,$i,"ship_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($array))];
      $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("minisigback.png"))
      exit;
if(!$bottom_img = @imagecreatefrompng("bottom_sign.png"))
      exit;

/*
*/
if ($debug == "true") {echo "break_3"."<br>";}

// make some colors
$white = imagecolorallocate($dest_img, 255, 255, 255);
$black = imagecolorallocate($dest_img, 0, 0, 0);
$red = imagecolorallocate($dest_img, 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);
}
?>
0
 
Richard QuadlingSenior Software DeveloperCommented:
You commented out the header().

THIS MUST BE UNCOMMENTED!!!!

0
 
Dodger42Author Commented:
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

0
 
Dodger42Author Commented:
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).

0
 
Richard QuadlingSenior Software DeveloperCommented:
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?
0
 
Dodger42Author Commented:
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.



0
 
Richard QuadlingSenior Software DeveloperCommented:
WHAT ERRORS?
0
 
Richard QuadlingSenior Software DeveloperCommented:
Can you manually create a quick page to allow access to the images as they are?
0
 
Dodger42Author Commented:
Wow... a stranger development. If I open up a web browser on the server itself, the images are displayed perfectly.

Bizarre!!
0
 
Dodger42Author Commented:
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.
0
 
Richard QuadlingSenior Software DeveloperCommented:
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.
0
 
Dodger42Author Commented:
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.
0
 
Dodger42Author Commented:
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.ico, referer: http://www.lomac-stats.com/sigs/42SFDodger.png

I have no idea what would be looking for that.
0
 
Dodger42Author Commented:
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.
0
 
Richard QuadlingSenior Software DeveloperCommented:
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/

0
 
Dodger42Author Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.