开发者

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?


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


getimagesize() seems to do the trick:

bits is the number of bits for each color.

doesn't even need GD.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜