ImageMagick执行命令,以减少白色背景的噪音PHP Imagick



我需要这一行:

magick "input.jpg" -fuzz 4% -transparent white -background white -alpha remove -alpha off -quality 85% "result.jpg"

:

$img = new Imagick($root . '/testall/imagemagick/input.jpg');
// ???
$img->setImageFormat('jpg');
$img->setImageCompressionQuality(85);
$img->writeImage($root . '/testall/imagemagick/result.jpg');

,我找不到fuzz在https://www.php.net/manual/de/book.imagick.php甚至开始。

请帮

你可以使用:Imagick::transparentPaintImage:

$img = new Imagick($root . '/testall/imagemagick/input.jpg');
$fuzz = 4 * Imagick::getQuantum(); // Copied from the example?
$img->transparentPaintImage('white', 0, $fuzz, false);
...

我尝试了andlrc答案,这是工作结果:

$img = new Imagick('input.jpg');
$fuzz = Imagick::getQuantum() * ($whitePercentage / 100);
$BackgroundColor = "rgb(255, 255, 255)";
$img->setImageFormat('png');
$img->transparentPaintImage($BackgroundColor, 0, $fuzz, false);
$img->setimagebackgroundcolor('white');
$img = $img->mergeImageLayers( imagick::LAYERMETHOD_FLATTEN );
$img->setImageFormat('jpg');
$img->setImageCompressionQuality($qualy);
$img->writeImage($root . '/testall/imagemagick/result.jpg');

最新更新