PHP raw 16-bit color

Is there a way to convert 16-bit (grayscale) PNG color to RGBA4444 color format using PHP?

-OR -

Is there any way to download this 16-bit black and white PNG using the RGBA4444 format?

The PNG header says it uses 16-bit color (bit depth) and shades of gray (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 , and $rgba is [A7, A7, A7, 0] .

By the way, here is the header of the specified 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 to follow this Charlie code ( https://stackoverflow.com/a/167498/ ). (Of course, with some changes.) Then convert each 16-bit color format (based on tEXt chunk) to the RGBA8888 format.

Then, pack() them in PNG format. But I still had an image error.

+6
source share
1 answer

Brad answered well. Trimming to 8 bits can be quite good with grayscale images. RGBA will end with a transparent image, which is probably not what you are really looking for. Have you tried to convert to a full-color 24-bit image? The result will still look like shades of gray, and you could simply reduce it to 8 bits with ease.

Using imagick will make this procedure much easier:

 convert source-image.png -evaluate multiply 16 -depth 8 destination-image.png 
+2
source

All Articles