當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP Gmagick setimagechanneldepth()用法及代碼示例


Gmagick::setimagechanneldepth()函數是PHP中的內置函數,用於設置特定通道圖像的深度。

用法:

Gmagick Gmagick::setimagechanneldepth( $channel , $depth )

參數:該函數接受上述和以下描述的兩個參數:


  • $channel:此參數用於指定通道常數。以下是固定頻道列表:
    CHANNEL constants:
    • Gmagick::CHANNEL_UNDEFINED
    • Gmagick::CHANNEL_RED
    • Gmagick::CHANNEL_GRAY
    • Gmagick::CHANNEL_CYAN
    • Gmagick::CHANNEL_GREEN
    • Gmagick::CHANNEL_MAGENTA
    • Gmagick::CHANNEL_BLUE
    • Gmagick::CHANNEL_YELLOW
    • Gmagick::CHANNEL_ALPHA
    • Gmagick::CHANNEL_OPACITY
    • Gmagick::CHANNEL_MATTE
    • Gmagick::CHANNEL_BLACK
    • Gmagick::CHANNEL_INDEX
    • Gmagick::CHANNEL_ALL
    • Gmagick::CHANNEL_DEFAULT
  • $depth:此參數用於指定要為Gmagick對象設置的深度。

返回值:成功時,此函數返回Gmagick對象。

以下示例程序旨在說明PHP中的Gmagick::setimagechanneldepth()函數:

示例1:
原始圖片:
https://media.geeksforgeeks.org/wp-content/uploads/geeks-21.png

<?php 
   
// Create new Gmagick object 
$im = new Gmagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-15.png'); 
   
// Using getImageChannelDepth function 
// with red channel 
echo "Before Set Channel depth: " . "</br>"; 
echo $im->getImageChannelDepth(Gmagick::CHANNEL_RED) . "</br>"; 
   
// Set channel Depth of CYAN and GREEN Channel 
$im->setimagechanneldepth(Gmagick::CHANNEL_RED, 4); 
   
echo "After Set Channel depth: " . "</br>"; 
echo $im->getImageChannelDepth(Gmagick::CHANNEL_RED) . "</br>"; 
  
?>

輸出:

Before Set Channel depth:
8
After Set Channel depth:
4

示例2:
原始圖片:
https://media.geeksforgeeks.org/wp-content/uploads/Screenshot-from-2018-10-16-23-23-54.png

<?php  
   
$string = "Computer Science portal for Geeks!";  
   
// Creating new image of above String  
// and add color 
$im = new Gmagick();  
$draw = new GmagickDraw();  
   
// Fill the color in image  
$draw->setFillColor(new GmagickPixel('green'));  
   
// Set the text font size  
$draw->setFontSize(50);  
   
$metrix = $im->queryFontMetrics($draw, $string);  
$draw->annotation(0, 40, $string);  
$im->newImage($metrix['textWidth'], $metrix['textHeight'],  
        new GmagickPixel('white'));  
   
// Draw the image          
$im->drawImage($draw);  
$im->setImageFormat('jpeg');  
   
// Using getImageChannelDepth function 
// with red channel 
echo "Before Set Channel depth: " . "</br>"; 
echo $im->getImageChannelDepth(Gmagick::CHANNEL_GREEN) . "</br>"; 
   
// Set channel Depth of Green Channel 
$im->setimagechanneldepth(Gmagick::CHANNEL_GREEN, 8); 
   
echo "After Set Channel depth: " . "</br>"; 
echo $im->getImageChannelDepth(Gmagick::CHANNEL_GREEN) . "</br>"; 
  
?>

輸出:

Before Set Channel depth:
16
After Set Channel depth:
8

參考: http://php.net/manual/en/gmagick.setimagechanneldepth.php



相關用法


注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | Gmagick setimagechanneldepth() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。