📜  PHP | imagick setSamplingFactors()函数

📅  最后修改于: 2022-05-13 01:56:30.009000             🧑  作者: Mango

PHP | imagick setSamplingFactors()函数

Imagick::setSamplingFactors()函数是PHP中的一个内置函数,用于设置图像采样因子。

句法:

bool Imagick::setSamplingFactors( array $factors )

参数:此函数接受单个参数$factors ,其中包含一个包含采样因子的关联数组。

返回值:此函数在成功时返回 TRUE。

异常:此函数在出错时抛出 ImagickException。

下面给出的程序说明了PHP中的Imagick::setSamplingFactors()函数

方案一:

PHP
setSamplingFactors(array('6', '7', '8'));
 
// Get the Sampling factors
$samplingFactors = $imagick->getSamplingFactors();
print("
".print_r($samplingFactors, true)."
"); ?>


PHP
setImageFormat('jpg');
 
// Set the sampling factors
$imagick->setSamplingFactors(array('1x1', '2x2'));
 
// Save the image
$compressed = $imagick->getImageBlob();
 
// Create a new imagick object
$reopen = new Imagick();
 
$reopen->readImageBlob($compressed);
 
// Resize it to same size
$reopen->resizeImage(667, 184, 0, 1);
 
// Show the output
header("Content-Type: image/jpg");
echo $reopen->getImageBlob();
?>


输出:

Array
(
    [0] => 6
    [1] => 7
    [2] => 8
)

方案二:

PHP

setImageFormat('jpg');
 
// Set the sampling factors
$imagick->setSamplingFactors(array('1x1', '2x2'));
 
// Save the image
$compressed = $imagick->getImageBlob();
 
// Create a new imagick object
$reopen = new Imagick();
 
$reopen->readImageBlob($compressed);
 
// Resize it to same size
$reopen->resizeImage(667, 184, 0, 1);
 
// Show the output
header("Content-Type: image/jpg");
echo $reopen->getImageBlob();
?>

输出:

参考: https://www. PHP.net/manual/en/imagick.setsamplingfactors。 PHP