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


PHP Imagick setCompression()用法及代碼示例

Imagick::setCompression()函數是PHP中的內置函數,用於設置對象的默認壓縮類型。

用法:

bool Imagick::setCompression( int $compression )

參數:此函數接受單個參數$compression,該參數持有與Imagick::COMPRESSION_ *常量之一匹配的整數。


返回值:成功時此函數返回TRUE。

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

程序1:

<?php 
  
// Create a new imagick object 
$imagick = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/20190823154611/geeksforgeeks24.png'); 
  
// Get the Compression 
$compression = $imagick->getCompression(); 
  
echo $compression; 
?>

輸出:

0 (which corresponds with imagick::COMPRESSION_UNDEFINED)

程序2:

<?php 
  
// Create a new imagick object 
$imagick = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/20190823154611/geeksforgeeks24.png'); 
  
// Set the Compression 
$imagick->setCompression(5); 
  
// Get the Compression 
$compression = $imagick->getCompression(); 
  
echo $compression; 
?>

輸出:

5 (which corresponds with imagick::COMPRESSION_JPEG)

參考: https://www.php.net/manual/en/imagick.setcompression.php



相關用法


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