php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #41080 #38794 also applies to imagegif and imagejpeg
Submitted: 2007-04-13 22:02 UTC Modified: 2007-05-25 22:39 UTC
From: rpeters+php at icomproductions dot ca Assigned: bjori (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: N/A
Private report: No CVE-ID: None
 [2007-04-13 22:02 UTC] rpeters+php at icomproductions dot ca
Description:
------------
Documentation for imagegif and imagejpeg both incorrectly convey that it is acceptable to pass null or an empty string as the second parameter without specifying additional parameters.

It is also worth noting that imagegif docs state it only takes 2 parameters, while other bug report comments have indicated it takes 4.

Related: bug #38794

Reproduce code:
---------------
imagegif($imageData, '');

Expected result:
----------------
According to the docs, this should be acceptable, causing the image to be outputted to the client.

Actual result:
--------------
It throws an exception trying to create a file with a null filename.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-25 20:12 UTC] bjori@php.net
Fixed imagegif(), imagejpeg() was fix long time ago
 [2007-05-25 20:25 UTC] rpeters+php at icomproductions dot ca
The doc experts are taken from ca.php.net, with modification dates of the 24th or 25th of May.

imagegif, and imagewbmp both report:

The path to the saved file. If not set or NULL, the raw image stream will be outputted directly.

imagejpeg reports:

To skip this argument in order to provide the quality parameter, use NULL.

None of these pages have appropriate warnings over the use of NULL.
I suggest taking inspiration from the imagepng page, which states:

Note: NULL is invalid if the quality and filters arguments are not used.

Again, I will note that imagegif is listed as having only 2 parameters while other bug reports indicate it accepts 4. If it does only take 2, then the documentation should refrain from specifying that filename can be set as null in any circumstances. (There are no valid combinations of two parameters where the second is null.)
 [2007-05-25 21:25 UTC] bjori@php.net
As I said. I fixed imagegif().
After reading the source more carefully NULL *IS* ok when libgd provides the gdImageGifCtx() function, same applies for imagewbmp() when compiled against libgd 1.5+.

imagegif() only has 2 arguments afaict, but does however not complain if passed 4arguments.

imagejpeg() docs are correct, to skip it (but wishing to pass quality) use null.
 [2007-05-25 21:50 UTC] rpeters+php at icomproductions dot ca
Perhaps I'm missing something. My test server is set up with PHP 5.1.6 (and perhaps this has become version dependant), and phpinfo reports:
GD Version: bundled (2.0.28 compatible)

I wrote the following code based on the current documentation on ca.php.net. I'm unsure if your changes have propagated there as of yet, but the modified date is today.

The following function will cause an exception if no third parameter is specified. (This is a simplified version of the code that prompted this bug report):

image_wrapper($type = "gif", $image = null, $filename = null)
{
  if($type == "gif")
    return imagegif($image, $filename);
  if($type == "wbmp")
    return imagewbmp($image, $filename);
  if($type == "png")
    return imagepng($image, $filename);
  if($type == "jpeg")
    return imagejpeg($image, $filename);
}

The current documentation (apart from that for imagepng) did not lead me to believe that I was doing anything wrong, and the exception thrown is not clear enough to understand what correction is required. This left me grasping at straws, finally requiring a google search to find out something that should be covered in the documentation.

To back up my assertion that the documentation needs to be specific in this case, look at the number of php bugs reported due to developers thinking the exception thrown by passing null as a second parameter was a mistake in PHP itself.

The alternative, of course, is to make the php functions more forgiving, but that has always been rejected in the aforementioned bug reports.
 [2007-05-25 22:39 UTC] bjori@php.net
[bjori@lindsay /usr/src/php/5.2]$ sapi/cli/php -r '$ret = array(); $im = imagecreatetruecolor(1,1);foreach(array("imagegif", "imagewbmp", "imagepng", "imagejpeg") as $func) { ob_start(); $func($im, null); $ret[$func]["out"] = ob_get_length(); ob_end_clean(); $func($im, $func); $ret[$func]["saved"] = strlen(file_get_contents($func));} var_dump($ret);'
array(4) {
  ["imagegif"]=>
  array(2) {
    ["out"]=>
    int(35)
    ["saved"]=>
    int(35)
  }
  ["imagewbmp"]=>
  array(2) {
    ["out"]=>
    int(5)
    ["saved"]=>
    int(5)
  }
  ["imagepng"]=>
  array(2) {
    ["out"]=>
    int(69)
    ["saved"]=>
    int(69)
  }
  ["imagejpeg"]=>
  array(2) {
    ["out"]=>
    int(695)
    ["saved"]=>
    int(695)
  }
}

null is perfectly acceptable as long as the underlaying libgd supports it and php was compiled correctly.

The imagegif() documentation have not been updated (no matter what your mirror thinks) and will not be updated in few days.


(_please_ specify your OS next time you report a bug): Are you running windows? If so there might be a bug in our windows configuration since afaik these ctx functions should be available when using the bundled libgd...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 16 16:01:34 2024 UTC