Imagick::opaquePaintImage()函數是PHP中的內置函數,用於將目標顏色替換為與目標顏色匹配的任何像素的指定填充顏色值。
用法:
bool Imagick::opaquePaintImage( $target, $fill, $fuzz, $invert, $channel = Imagick::CHANNEL_DEFAULT ] )
參數:該函數接受上述和以下所述的五個參數:
- $target:此參數保存需要更改的ImagickPixel對象或目標顏色。
- $fill:此參數保留要替換的顏色。
- $fuzz:此參數保存浮點類型的模糊量。
- $invert:在0和1之間切換,其中0為正常,1為反。
- $channel:該參數保存Imagick通道常數,該常數提供對通道模式有效的任何通道常數。可以使用按位運算符組合多個通道。
返回值:如果成功,此函數返回TRUE;如果失敗,則返回FALSE。
以下示例程序旨在說明PHP中的Imagick::opaquePaintImage()函數:
示例1:
<?php
// Image Path
$imagePath =
"https://cdncontribute.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-9.png";
// Target color
$target = 'rgb(255, 255, 255)';
// Replacing target color with another color
$fill = 'rgb(255, 234, 128)';
$fuzz = '0.1';
// Initialize invert variable
$invert = '0';
$imagick = new \Imagick($imagePath);
// Set the image format
$imagick->setimageformat('png');
$imagick->opaquePaintImage(
$target, $fill, $fuzz * \Imagick::getQuantum(), $invert
);
// Use despeckleimage() function to reduce
// the speckle noise in an image
$imagick->despeckleimage();
header("Content-Type: image/png");
// Display the output image
echo $imagick->getImageBlob();
?>
輸出:
示例2:
<?php
// Image Path
$imagePath =
"https://media.geeksforgeeks.org/wp-content/uploads/20190826021518/checkerboardgfg.png";
// Target color
$target = 'rgb(255, 255, 255)';
// Replacing target color with another color
$fill = 'rgb(21, 200, 236)';
$fuzz = '0.1';
// Initialize invert variable
$invert = '0';
$imagick = new \Imagick($imagePath);
// Set the image format
$imagick->setimageformat('png');
$imagick->opaquePaintImage(
$target, $fill, $fuzz * \Imagick::getQuantum(), $invert
);
header("Content-Type: image/png");
// Display the output image
echo $imagick->getImageBlob();
?>
輸出:
參考: https://www.php.net/manual/en/imagick.opaquepaintimage.php
相關用法
- PHP Imagick getImageCompose()用法及代碼示例
- PHP Imagick getImageChannelStatistics()用法及代碼示例
- PHP Imagick setImageClipMask()用法及代碼示例
- PHP Imagick getImageChannelExtrema()用法及代碼示例
- PHP Imagick getImageChannelMean()用法及代碼示例
- PHP Imagick getImageClipMask()用法及代碼示例
- PHP Imagick haldClutImage()用法及代碼示例
- PHP Imagick getImageBackgroundColor()用法及代碼示例
- PHP Imagick getImageChannelDistortion()用法及代碼示例
- PHP Imagick setImageBluePrimary()用法及代碼示例
- PHP Imagick getImageBorderColor()用法及代碼示例
- PHP Imagick setImageBackgroundColor()用法及代碼示例
- PHP Imagick setImageBorderColor()用法及代碼示例
- PHP Imagick setImageCompose()用法及代碼示例
- PHP Imagick setImageDelay()用法及代碼示例
注:本文由純淨天空篩選整理自VigneshKannan3大神的英文原創作品 PHP | Imagick opaquePaintImage() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。