2

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?

shapeshifta
  • 300
  • 5
  • 16

2 Answers2

1

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

Community
  • 1
  • 1
bcosca
  • 17,371
  • 5
  • 40
  • 51
  • Hey there, your information is quite valuable, but it does not solve my problem, because there is no metadata in the files which would tell me if it is a png-8 or a png-24. I only get "Software: ImageReady" because they were made in Photoshop. – shapeshifta Nov 05 '10 at 09:44
1

getimagesize() seems to do the trick:

bits is the number of bits for each color.

doesn't even need GD.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • 1
    yeah, I know, but getimagesize() does return 8 for png-8 and png-24 as well... :( – shapeshifta Nov 05 '10 at 17:12
  • @shapeshifta strange. How many channels does it show for png-24? – Pekka Nov 05 '10 at 17:13
  • @Pekka: I am afraid, but it does not show any channels for png, but there should be 3 because it's rgb. on the other hand getimagesize() seems to show the correct values for my other images such as jpg or gifs(which could be quite incorrect as the documentation states)... – shapeshifta Nov 06 '10 at 14:46
  • ... maybe I could just check if it's truecolor, but I wonder why it doesn't imagecolorstotal() does not return any colors for png-24 as it does return 256 for png-8 ... mooh! – shapeshifta Nov 06 '10 at 14:48
  • @shapeshifta really odd! It's *supposed* to give that information. That sounds like a bug. Re `imagecolorstotal()`, when you do that on the image, it is already too late: It's been imported into GD's colour space, which is always 8 bits per channel. – Pekka Nov 06 '10 at 16:33
  • Hm, I will get a vm and try with imagemagick. Thanks for your help :) – shapeshifta Nov 10 '10 at 07:53