PHP PNG image file parsing
Hi, I've just started messing with PHP and Apache, and knocked up the below quick script as a quirky idea. It's meant to read the hex colours of each pixel of a PNG file, and then print them as the colour for the background of a table division in a html page.
It does result in a grid of coloured cubes but my problem is the colour is wrong compared to the source image viewed enlarged in, say, the Gimp. I suspect the problem lies in the int->hex code I copied from the PHP Manual, with the bitshifting and masking. PHP Code:
|
all i can think of would be that php may be set to only work with web standard colors, only 255. wheras your image may b in high, or true, colors, a lot more.
|
Well I improved the code and it works now well, except for not using the transparency values of the pixels. :)
PHP Code:
|
You can also short your code by replace your last if blocks by conditional statement like :
PHP Code:
|
Nice! Thanks :)
|
All times are GMT -5. The time now is 04:06 AM. |