Rei*_*ugh 6 php image-processing
有没有办法使用PHP将16位(灰度)颜色PNG转换为RGBA4444颜色格式?
-要么-
有没有办法使用RGBA4444格式加载这个16位灰度PNG?
PNG标题表示它使用的是16位颜色(位深度)和灰度颜色(颜色类型)(http://www.fileformat.info/format/png/corion.htm,IHDR图像标题).
$rgb = imagecolorat($src, $x, $y);
var_dump("RGB - ".dechex($rgb));
$rgba = imagecolorsforindex($src, $rgb);
var_dump("RGBA - ".dechex($rgba));
Run Code Online (Sandbox Code Playgroud)
的值$rgb(举例来说)是A7同时$rgba是[A7, A7, A7, 0].
顺便说一句,这是所述文件的标题:
89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 | .PNG........IHDR
00 00 03 FF 00 00 03 FF 10 00 00 00 00 E3 F9 FF | ................
C9 00 00 00 0D 74 45 58 74 44 46 4D 54 00 52 34 | .....tEXtDFMT.R4
47 34 42 34 41 34 E0 94 BA 92 00 00 20 00 49 44 | G4B4A4........ID
41 54 .. .. | AT
Run Code Online (Sandbox Code Playgroud)
编辑:
我首先做的是遵循Charlie的这段代码(/sf/answers/510540061/).(当然有一些修改.)然后将每个16位颜色格式(基于tEXt块)转换为RGBA8888格式.
然后,pack()他们以PNG文件格式.但我仍然有图像错误.
布拉德的回答还不错。对于灰度图像来说,截断到 8 位就足够了。RGBA 将以透明图像结束,这可能不是您真正想要的。您是否已尝试转换为全彩 24 位图像?结果仍然看起来像灰度,您可以轻松地将其降低到 8 位。
使用 imagick 将使这个过程变得更加简单:
convert source-image.png -evaluate multiply 16 -depth 8 destination-image.png
Run Code Online (Sandbox Code Playgroud)