在 PHP 中,imagepng() 接受过滤器参数。这些过滤器如何影响函数的输出?
这些过滤器如何影响 PHP 中 imagepng() 的输出?
- PNG_NO_FILTER
- PNG_FILTER_NONE
- PNG_FILTER_SUB
- PNG_FILTER_UP
- PNG_FILTER_AVG
- PNG_FILTER_PAETH
- PNG_ALL_FILTERS
文档只是说,“一个特殊的 PNG 滤镜,由 imagepng() 函数使用”。
似乎使用 PNG_NO_FILTER 会减少输出的文件大小,但除此之外,我不确定它是如何受到影响的。任何见解将非常感激。
How do these filters affect the output of imagepng() in PHP?
- PNG_NO_FILTER
- PNG_FILTER_NONE
- PNG_FILTER_SUB
- PNG_FILTER_UP
- PNG_FILTER_AVG
- PNG_FILTER_PAETH
- PNG_ALL_FILTERS
The documentation simply says, "A special PNG filter, used by the imagepng() function" for each of them.
It seems that using PNG_NO_FILTER will reduce the filesize of the output, but other than that, I am unsure as to how it is affected. Any insight would be really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 http://www.w3.org/TR/PNG-Filters 上的 PNG 规范.html 这些过滤器的目的是准备图像数据以实现最佳压缩。
According to the PNG Specifications at http://www.w3.org/TR/PNG-Filters.html The purpose of these filters is to prepare the image data for optimum compression.
从链接到问题的 imagepng() 手册页中,
因此,要让 libpng 尝试 none、sub 和 up 过滤器,您可以使用
PNG_ALL_FILTERS 只是简写。
至于使用哪个过滤器,这取决于图像。具有 256 种或更少颜色的图像通常使用 PNG_NO_FILTER 压缩效果更好,而具有多种颜色的图像(例如照片)通常使用 PNG_FILTER_SUB 或 PNG_ALL_FILTERS 压缩效果更好。 “optipng”或“pngcrush”等应用程序尝试优化过滤器选择。如果您打算使用这些第三方应用程序之一进行最终优化,则应该仅对工作副本使用 PNG_NO_FILTERS,以提高速度。
From the imagepng() man page linked to the question,
So, to let libpng try the none, sub, and up filters, you'd use
PNG_ALL_FILTERS is just shorthand for
As for which filter to use, it depends upon the image. Images with 256 or fewer colors generally compress better with PNG_NO_FILTER, while images with many colors (such as photos) generally compress better with PNG_FILTER_SUB or PNG_ALL_FILTERS. Applications like "optipng" or my "pngcrush" try to optimize the filter selection. If you're going to use one of those third-party applications for final optimization, you should just use PNG_NO_FILTERS for your working copies, for speed.
这些都是 PNG 编码器可以用来确定像素值的不同算法。不太了解,但此页面似乎有些深入: http: //www.w3.org/TR/PNG-Filters.html
Those are all different algorithms the PNG encoder can use to determine pixel values. Don't know a whole lot, but this page seems to go into some depth: http://www.w3.org/TR/PNG-Filters.html