tags:

views:

731

answers:

1

I have a need to read in the exact unaltered pixel data (ARGB) from a truecolour PNG file, preferably from PHP.

Unfortunately the GD library in PHP messes with the alpha channel (reducing it from 8-bit to 7-bit), making it unusable.

I'm currently assuming that my options are either:

  1. Implement my own raw PNG reader to extract the necessary data.
  2. Use some less-broken language/library and call it from the PHP as a shell process or CGI.

I'd be interested to hear any other ideas, though, or recommendations for one way over the other...

Edit: I think #1 is out. I've tried passing the IDAT data stream to gzinflate(), but it just gives me a data error. (Doing the exact same thing, with the exact same data, outside of PHP produces the expected result.)

+2  A: 

How about ImageMagick?

<?php
$im = new Imagick("foo.png");
$it = $im->getPixelIterator();

foreach($it as $row => $pixels) {
    foreach ($pixels as $column => $pixel) {
        // Do something with $pixel
    }

    $it->syncIterator();
}
?>
Can Berk Güder
http://us.php.net/imagick
slacy
Unfortunately I'm stuck with PHP4 at the moment, and ImageMagick is not installed on the server (nor does it appear to be compatible).
Miral