如何使用php找到PNG图像的通道数?
根据 getimagesize 的文档(http://php.net/manual/en/function.getimagesize.php),这个函数似乎总是会返回通道数。
据我所知,情况并非如此。这是一个例子:
通道测试.php:
<?php
$path1 = "test.jpg";
$path2 = "homer.gif";
$path3 = "bmp_24.bmp";
$path4 = "tux.png";
$info1 = getimagesize($path1);
$info2 = getimagesize($path2);
$info3 = getimagesize($path3);
$info4 = getimagesize($path4);
echo "\nJPG:";
print_r($info1);
echo "\nGIF:";
print_r($info2);
echo "\nBMP:";
print_r($info3);
echo "\nPNG:";
print_r($info4);
?>
channel_test.php 的输出:
JPG:Array
(
[0] => 463
[1] => 399
[2] => 2
[3] => width="463" height="399"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)
GIF:Array
(
[0] => 320
[1] => 320
[2] => 1
[3] => width="320" height="320"
[bits] => 8
[channels] => 3
[mime] => image/gif
)
BMP:Array
(
[0] => 200
[1] => 200
[2] => 6
[3] => width="200" height="200"
[bits] => 24
[mime] => image/x-ms-bmp
)
PNG:Array
(
[0] => 400
[1] => 479
[2] => 3
[3] => width="400" height="479"
[bits] => 8
[mime] => image/png
)
如您所见,没有为 BMP 和 PNG 图像返回通道数。这是错误还是预期行为?如果它是预期的,我认为 php 文档有点误导。
还有其他方法可以获取频道数吗?
我正在运行 php 5.4.9 (linux),安装了 gd 和 imagick。