|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 22 06:00:01 2025 UTC |
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.[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...