Is there a way to convert a 16-bit (grayscale) color PNG to an RGBA4444 color format using PHP?
-OR-
Is there a way to load this 16-bit grayscale PNG using RGBA4444 format?
The PNG header says that it is using 16-bit color (Bit depth) and grayscale color (Color type) (http://www.fileformat.info/format/png/corion.htm, IHDR Image Header).
$rgb = imagecolorat($src, $x, $y);
var_dump("RGB - ".dechex($rgb));
$rgba = imagecolorsforindex($src, $rgb);
var_dump("RGBA - ".dechex($rgba));
The value of $rgb
(for example) is A7
while $rgba
is [A7, A7, A7, 0]
.
BTW, here is the header of the said file:
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
EDIT:
What I did first was follow this code by Charlie (https://stackoverflow.com/a/7293429/2205703). (Of course with some modification.) Then convert each 16-bit color format (based on tEXt
chunk) to RGBA8888 format.
Then, pack()
them to PNG file format. But I still got image error.
Brad's answer's not bad. Truncating to 8 bit could be good enough with grayscale images. RGBA would end in an transparent image that is probably not what you're really looking for. Did you allready tried to to convert to a full-color 24 bit image? The result would be still looking a like grayscale they you could simply reduce it to 8 bit with ease.
Using imagick would make this procedure much simpler:
convert source-image.png -evaluate multiply 16 -depth 8 destination-image.png