php - How to check a PNG for grayscale/alpha color type? -
php , gd seem have trouble creating images pngs of type greyscale alpha when using imagecreatefrompng(). results incredibly distorted. 
i wondering if knew of way test colour type in order notify user of incompatibility?
example:
original image: http://dl.dropbox.com/u/246391/robin.png
 resulting image: http://dl.dropbox.com/u/246391/robin_result.png
code:
<?php  $resource = imagecreatefrompng('./robin.png'); header('content-type: image/png'); imagepng($resource); imagedestroy($resource);   cheers,
aron
the colour type of png image stored @ byte offset 25 in file (counting 0). if can hold of actual bytes of png file, @ byte 25 (i don't php, don't know how that):
- 0 - greyscale
 - 2 - rgb
 - 3 - rgb palette
 - 4 - greyscale + alpha
 - 6 - rgb + alpha
 
the preceding byte (offset 24) gives number of bits per channel. see the png spec more details.
in slight twist png file may have "1-bit alpha" (like gifs) having trns chunk (when colour type 0 2 or 3).
Comments
Post a Comment