shapeshifta
shapeshifta

Reputation: 298

How to tell if image is PNG24 or PNG8 and the number of bits and channels?

I am trying to distinguish PNG-8 and PNG-24 images with getimagesize or Imagick, but I don't quite know how to to it.

getimagesize does not return channels for my PNGs and displays the mimetype instead. It works well for other images and shows the correct values, but for PNG it just shows nothing.

edit: Imagick is not installed in my environment but gdlib is...

Can anyone help me a bit?

Greetings,
Tom

edit2: Is it possible to do it like this?

    //create png for tests
    $testPng = imagecreatefrompng( $file );
    //test how many colors are used
    $meta .= 'colors: ' . imagecolorstotal( $testPng );
    $meta .= ' truecolor: ' . imageistruecolor( $testPng );
    //destroy the test image
    imagedestroy( $testPng );

And if truecolor is false or not set, it is a png24?

Upvotes: 2

Views: 1867

Answers (2)

Pekka
Pekka

Reputation: 449415

getimagesize() seems to do the trick:

bits is the number of bits for each color.

doesn't even need GD.

Upvotes: 1

bcosca
bcosca

Reputation: 17555

Take a look at How can I read PNG Metadata from PHP?

Upvotes: 1

Related Questions