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

From: Date: Wed, 05 Apr 2017 10:10:24 +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-14583@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:

looks great thx. wasnt aware of the tool, will play with it in the future. thx!


Previous Comments:
------------------------------------------------------------------------
[2017-04-05 09:16:11] peehaa@php.net

Does this work for you?

Create a patch here http://edit.php.net/?patchID=2445&project=PHP

------------------------------------------------------------------------
[2017-04-03 10:23:35] maggus dot staab at googlemail dot com

I guess you are right. when the default of "6" is mentioned this might already ring a bell
that 9 is not the best for some reason in all cases ;-).

thanks!

------------------------------------------------------------------------
[2017-04-03 09:54:36] requinix@php.net

The average PHP developer doesn't know about the structure of PNG images or about zlib
compression, so telling them the default is Z_DEFAULT_COMPRESSION will just confuse them. Similarly,
drowning them in information about the relationship between compression level and file size/runtime
will have their eyes glossing over.

I'd keep it simple: the default level is 6 [I doubt it will change anytime soon] and is a good
compromise between the speed of level=0 and the compression of level=9.

If there's something more in-depth to be said then it would probably be best as a link to some
external resource - minimizing the number of pages in the manual that can only be maintained by
people with specialized knowledge.

------------------------------------------------------------------------
[2017-04-03 09:31:21] maggus dot staab at googlemail dot com

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

------------------------------------------------------------------------
[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).

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=74364


--
Edit this bug report at https://bugs.php.net/bug.php?id=74364&edit=1


Thread (8 messages)

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