如何判断图像是PNG24还是PNG8以及位数和通道数?

发布于 2024-10-01 02:39:32 字数 619 浏览 1 评论 0原文

我试图用 getimagesize 或 Imagick 来区分 PNG-8 和 PNG-24 图像,但我不太知道如何做。

getimagesize 不会返回我的 PNG 的通道,而是显示 mimetype。它适用于其他图像并显示正确的值,但对于 PNG 它只显示任何内容。

编辑:我的环境中没有安装 Imagick,但 gdlib 是...

任何人都可以帮助我吗?

您好,
汤姆

编辑2: 可以这样做吗?

    //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 );

如果 truecolor 为 false 或未设置,它是 png24?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃素的狼 2024-10-08 02:39:32

getimagesize() 似乎可以解决问题:

bits 是每种颜色的位数。

甚至不需要GD。

getimagesize() seems to do the trick:

bits is the number of bits for each color.

doesn't even need GD.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文