📜  PHP |想象一下 setImageDepth()函数

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

PHP |想象一下 setImageDepth()函数

Imagick::setImageDepth()函数是PHP中的一个内置函数,用于设置特定图像的深度。
句法:

bool Imagick::setImageDepth( $depth )

参数:此函数接受单个参数$depth ,它是一个整数值,用于设置图像的深度。
返回值:此函数在成功时返回 true。
下面的程序说明了PHP中的Imagick::setImageDepth()函数:
原图:

方案一:

php
getImageDepth();
   
// Display the depth of image
echo "Previous Depth" . $res;
 
$image->setImageDepth(20);
 
$res = $image->getImageDepth();
echo "
After Set Depth" . $res; ?>


php
setFillColor(new ImagickPixel('green'));
    
// Set the text font size
$draw->setFontSize(50);
    
$matrix = $im->queryFontMetrics($draw, $string);
$draw->annotation(0, 40, $string);
$im->newImage($matrix['textWidth'], $matrix['textHeight'],
         new ImagickPixel('white'));
             
// Draw the image         
$im->drawImage($draw);
    
$im->setImageFormat('jpeg');
 
$dpth = $im->getImageDepth();
    
// Display the depth of image
print("Previous Depth = " . $dpth);
  
$im->setImageDepth(20);
$dpthnew = $im->getImageDepth();
  
// Display the depth of image
print("
Depth After Set  = " . $dpthnew); ?>


输出:

Previous Depth 8
After Set Depth 20

原图:

https://media.geeksforgeeks.org/wp-content/uploads/Screenshot-from-2018-10-16-23-23-54-1.png

方案二:

PHP

setFillColor(new ImagickPixel('green'));
    
// Set the text font size
$draw->setFontSize(50);
    
$matrix = $im->queryFontMetrics($draw, $string);
$draw->annotation(0, 40, $string);
$im->newImage($matrix['textWidth'], $matrix['textHeight'],
         new ImagickPixel('white'));
             
// Draw the image         
$im->drawImage($draw);
    
$im->setImageFormat('jpeg');
 
$dpth = $im->getImageDepth();
    
// Display the depth of image
print("Previous Depth = " . $dpth);
  
$im->setImageDepth(20);
$dpthnew = $im->getImageDepth();
  
// Display the depth of image
print("
Depth After Set  = " . $dpthnew); ?>

输出:

Previous Depth = 8
Depth After Set = 20

参考: http: PHP。 PHP