2

I have installed a piece of code on a website, wich includes gd functions. After debugging I came to a conclusion that the

$src = imagecreatefrompng($s);

is causing the server to respond: "Connection was reset" Even if I change the code to:

$src = @imagecreatefrompng($s);

The same error occurs. I have checked the php version, checked if gd library is installed and enabled, but everything is ok. There is nothing in the error_log. Also, the file path is all right, the file exists, and other functions can access the file (like fopen or file_get_contents), so there is no problem with the rights.

Anyone has an idea?

Edit: The file is on a local server.

Ernest Marcinko
  • 405
  • 3
  • 12
  • Hey Ernest, this doesn't really sound like anything that could be caused by GD. Could you try writing a basic GD php file to see if the problem still persists? try something like the sample from here: http://php.net/manual/en/function.imagestring.php – Shai Mishali Jan 26 '12 at 10:00
  • Do you get the image from a remote server? If so, you should use `imagecreatefromstring(file_get_contents($s));` first. (http://php.net/manual/en/function.imagecreatefromstring.php) – Quasdunk Jan 26 '12 at 10:03
  • Shai Mishali: I have tried the first example from the site you linked, and the result was successful. – Ernest Marcinko Jan 26 '12 at 10:14
  • Quasdunk - The file is on the local server. – Ernest Marcinko Jan 26 '12 at 10:15
  • @ErnestMarcinko Please can you ensure you have `error_reporting(E_ALL); ini_set('display_errors', 1);` at the top of the script and see if you get any more useful error messages – DaveRandom Jan 26 '12 at 10:24
  • @DaveRandom - Nothing happens, no error messages, just the connection reset error. – Ernest Marcinko Jan 26 '12 at 10:27
  • Is that a PHP error, or the output of your script? I.e. where do you see the string error "Connection was reset", and what is the FULL string? – DaveRandom Jan 26 '12 at 10:30
  • @DaveRandom - It's not like a php error, it's a server error, like when you open a domain wich does not exists. Like this: http://fc03.deviantart.net/fs70/f/2011/127/f/7/the_connection_was_reset_by_s3k4rep-d3fs7ze.png – Ernest Marcinko Jan 26 '12 at 10:47
  • Oh like an actual HTTP error? That is interesting, it suggests that PHP has just crashed - can you run the script from the command line? If so, try it and see what you get (if it is a *nix server I suspect you may see the string `SIGSEGV` if the script is dying with no error) - if this is the case it may due to a corrupted input file - can you open the image in an image viewer on your PC? – DaveRandom Jan 26 '12 at 10:54
  • @DaveRandom - Unfortunately I cannot access the server by command line. I have double checked the image file, and it's not corrupted. I contacted the server administrator to reinstall gd and php, it may solve the problem. I can't think of anything else. – Ernest Marcinko Jan 26 '12 at 11:06
  • @ErnestMarcinko How large is the image file you are trying to open? It may also help to add the code surrounding the way that you call `imagecreatefrompng()` to the question - notably how you are constructing `$s`, whether the code is called in a loop, function etc - if you can add the relevant code block to the question we can look at it and see if there are any obvious errors, although from what you say I doubt this is the case and I suspect that the problem is an internal PHP one. What version of PHP/GD is the server currently running? (`phpinfo()`) – DaveRandom Jan 26 '12 at 11:16
  • @DaveRandom GD - bundled (2.0.34 compatible) PHP - Version 5.3.9 The image size is 1x56 px, not corrupted, png, not in a loop, the function is called one time. $s is 100% okay, I tested it with fopen, file_get_contents, printed it out, also checked manually if the file really exists. – Ernest Marcinko Jan 26 '12 at 12:18

1 Answers1

1

Hmm, if you can't access the server via command line you may have some headaches tracking this down. 2 things that come to mind:

  1. It's unlikely, yet possible libpng is not installed, or gd wasn't compiled w/ PNG support. Run phpinfo() from the browser and look for the gd section, you should see PNG support 'enabled' there.
  2. The image might not be a PNG image! I know it's wacky but these things can happen, just naming a file .png does not a PNG file make, haha. If you have ImageMagick you can use the identify program to check, here's a run from my laptop:

    $ identify ~/transparent-pixel.png ~/transparent-pixel.png PNG 1x1 1x1+0+0 8-bit DirectClass 2.79KB 0.010u 0:00.009

There are probly some other programs you can use to verify the image is indeed an PNG.

Lastly, I would suggest getting your script to work in a local environment that simulates the server, like a VM or similar. That should help you track down the issue on the server w/o quite as many headaches.

quickshiftin
  • 66,362
  • 10
  • 68
  • 89