在php中将现有的图像(8位,32位等)转换为24位png


Converting an existing image(8 bit, 32 bit etc) to 24 bit png in php

如何将现有的png图像转换为24位png图像。

现有图像可以是8位、16位、32位、48位或64位。我想把它们全部转换成24位png图像。

我尝试imagemagick在我的本地主机(windows 7)使用php以下是我尝试过的命令。

shell_exec('C:''imagemagick''convert -depth 24 sentences.png sentences2.png');

shell_exec('C:''imagemagick''convert sentences.png -transparent white png24:sentences2.png');

以上都不适合我。以上脚本以随机位深度转换图像。例如,如果句子。png是8位深度,转换后它变成32位。类似地,对于其他图像,它变为32位,有时变为48位等。

如何正确实现从任何png到24位png的转换?

可以这样使用Imagick PHP函数:

$imagick_image = new Imagick($image_filename);
$imagick_image->writeImage("png24:$image_filename");