Doc #74364 [Ver]: imagepng misses default value for $quality param

From: Date: Mon, 03 Apr 2017 09:31:26 +0000
Subject: Doc #74364 [Ver]: imagepng misses default value for $quality param
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-14572@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74364&edit=1 ID: 74364 User updated by: maggus dot staab at googlemail dot com Reported by: maggus dot staab at googlemail dot com Summary: imagepng misses default value for $quality param Status: Verified Type: Documentation Problem Package: GD related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: thx for your in-depth analysis. things seem to be more complicated then initially thought ;-). would it make sense to mention in the docs that the param defaults to zlibs default compresssion Z_DEFAULT_COMPRESSION ? maybe it would also be worthwhile when it will be mentioned that this parameter is not a linear 0 is worst and 9 is best compression thing but the "optimal" value lies somehow in the middle? A lot of people are used to jpeg which works best when doing the most aggressive optimization ahead of time. see also http://marcjschmidt.de/blog/2013/10/25/php-imagepng-performance-slow.html Previous Comments: ------------------------------------------------------------------------ [2017-04-03 07:52:51] requinix@php.net tldr: The default depends on zlib but is probably 6. :375 is not quite the right place. That does define the arguments but is not where the defaults are - see how everything uses 0? To see the default you have to check the code in the function itself (:2747). However that just passes execution to _php_image_output_ctx (gd_ctx.c:82), which does extract the arguments (:120) with quality=$quality. Then it sets q=quality if it had been passed to the function (:129) or else it will remain with its initial value of -1 (:91). GD gets involved later (:202) by calling *func_p, which was an argument passed to _php_image_output_ctx (from back in gd.c) and, in the case of imagepng, is gdImagePngCtxEx. At this point you hit up Google and find https://libgd.github.io/manuals/2.2.2/files/gd_png-c.html where gdImagePngCtxEx says the default compression is -1 too. Jump to "gdIamgePnEx" (lol) and you get > A compression level of -1 will use the default compression level at the time > zlib was compiled on your system. Back to Google one more time and we find http://www.zlib.net/manual.html > Compression levels. > #define Z_DEFAULT_COMPRESSION (-1) ... > Z_DEFAULT_COMPRESSION requests a default compromise between speed and compression > (currently equivalent to level 6). ------------------------------------------------------------------------ [2017-04-03 07:15:34] maggus dot staab at googlemail dot com Description: ------------ the docs mention the valid for $quality spans from 0-9 but it doesnt mention what the default value is. it defaults to 0 it seems (dont rely on my non-existent C-fu tho) https://lxr.room11.org/xref/php-src%40master/ext/gd/gd.c#375 --- From manual page: http://www.php.net/function.imagepng --- ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74364&edit=1

« previous php.doc.bugs (#14572) next »