php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #38794 imagepng: second parameter must not be '' or NULL
Submitted: 2006-09-12 16:09 UTC Modified: 2007-01-23 01:48 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: bytewise at gmx dot net Assigned: pajoye (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bytewise at gmx dot net
New email:
PHP Version: OS:

 

 [2006-09-12 16:09 UTC] bytewise at gmx dot net
Description:
------------
The documentation of imagepng (in English and German) states that the second parameter may be null or the empty string:

"
bool imagepng ( resource image [, string filename] )
The filename argument is optional, and if left off or filled with a NULL value, the raw image stream will be output directly.
"

This is not the case, at least in php 5.1.6 this function does not work anymore if given an empty string or null as second parameter. It will merely generate a warning ("Unable to open '' for writing"), and output some trash, not a real png image.

This problem is NOT related to sending a bad header.

The same code worked fine for me in php 5.0.4; after an upgrade to 5.1.6 it stopped working. I removed the second  (null) parameter to imagepng, and it worked again. Only it took a couple of hours to find out :)

There at least 2 bug reports that are related to this, both  of which have been closed (nothing having been done about them):
http://bugs.php.net/35061
http://bugs.php.net/36464


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-12 18:23 UTC] pajoye@php.net
The function accepts the following arguments set:
imagepng($im, "filename"); save $im as filename

# save $im as filename, using compression and $filter
imagepng($im, "filename", $compression, $filter);

# Output $im, using compression and $filter
imagepng($im, NULL, $compression, $filter);

NULL is invalid if the compression and filter arguments are not used.
 [2006-09-12 19:14 UTC] bytewise at gmx dot net
Then I guess the documentation *really* needs an update, because it looks totally different. There is no mention of the quality and filter arguments.

Additionally, the empty string is *also* invalid, not only NULL.
 [2006-09-17 04:53 UTC] fletch at pobox dot com
This is also present, at least in imagepng(), in 5.1.4.

imagepng( $img, NULL ) triggers this error:

Warning: imagepng() [function.imagepng]: Unable to open '' for writing
 [2007-01-23 01:48 UTC] didou@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of didou
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=44e4dfc6f68c30a35bbee22805641374b9fc2db6
Log: Fix #38794: Document the new filters parameter for imagepng() Also add a note about filename usage
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 13:01:33 2025 UTC