在 PHP GD 中,PNG_ALL_FILTERS
的作用是什么?它与 png 图像的“自适应过滤”有何关系?
背景
在 php 中,GD 库中的 imagepng
函数有一个过滤器参数。 documentation on the filter type constants allowed仅“揭示”这些常量表示:
A special PNG filter, used by the imagepng() function
确实很有帮助。
This answer在 SO 上讲述了更多信息,但缺少有关常量 PNG_ALL_FILTERS
的信息。在我看来,其他过滤器似乎是相互排斥的,那么“全部”是做什么的?
在我的搜索中,我发现对于 png 过滤,一个好的策略(在某些情况下)是为每个扫描线分别选择最佳过滤器,称为“自适应过滤”。
考虑到上述情况,我猜想“自适应过滤”是通过 PNG_ALL_FILTERS
选项完成的。我猜对了吗?如果不是, PNG_ALL_FILTERS
做什么?我可以让 GD 从 php 进行自适应过滤吗?
非常感谢!
最佳答案
GD 使用 libpng。
libpng 联机帮助页基本上说明了 pngimage 描述所说的内容。如果那“远非确认”,那么您将需要阅读 libpng 源以进行确认。在libpng的png.h中定义了宏:
/* Flags for png_set_filter() to say which filters to use. */
#define PNG_NO_FILTERS 0x00
#define PNG_FILTER_NONE 0x08
#define PNG_FILTER_SUB 0x10
#define PNG_FILTER_UP 0x20
#define PNG_FILTER_AVG 0x40
#define PNG_FILTER_PAETH 0x80
#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
PNG_FILTER_AVG | PNG_FILTER_PAETH)
宏在png_write_find_filter()中使用,包含如下代码:
if (filter_to_do & PNG_FILTER_SUB)
[calculate figure of merit for the SUB filter]
else if (filter_to_do & PNG_FILTER_UP)
[calculate figure of merit for the UP filter]
...
else if (filter_to_do & PNG_FILTER_PAETH)
[calculate figure of merit for the PAETH filter]
然后为正在写入的扫描线选择品质因数最低的滤波器。 PNG_ALL_FILTERS 宏只是提供了一种启用所有过滤器进行测试的简便方法。
关于php - PNG_ALL_FILTERS,php gd中的自适应过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23455384/