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


PHP imageaffine()用法及代碼示例

imageaffine()函數是PHP中的內置函數,用於使用可選的剪切區域獲取包含仿射變換的src圖像的圖像。仿射是涉及矩陣的幾何變換操作。

用法:

resource imageaffine( resource $image, array $affine, array $clip )

參數:此函數接受上述和以下所述的三個參數:


  • $image:它指定圖像資源。
  • $affine:它使用鍵0到5指定數組。
  • $clip:它指定要裁剪的區域。

返回值:如果成功,此函數返回關聯的圖像資源,如果失敗,則返回FALSE。

異常:該函數在出錯時引發Exception。

下麵給出的程序說明了PHP中的imageaffine()函數:

程序1:

<?php 
  
// Create a image from url 
$im = imagecreatefrompng( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Affine the image 
$newimage = imageaffine($im, [ -1.3, 0, 0, -0.7, 0, 0 ]); 
  
// Output the image 
header('Content-Type:image/png'); 
imagepng($newimage); 
?>

輸出:

程序2:

<?php 
  
// Create a image from url 
$im = imagecreatefrompng( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
$clipped = [ 
    'x' => 0, 
    'y' => 0, 
    'width' => 200, 
    'height' => 200, 
]; 
  
// Affine the image 
$newimage = imageaffine($im, [-1, 0, 0, sin(4), 0, 0], $clipped); 
  
// Output the image 
header('Content-Type:image/png'); 
imagepng($newimage); 
?>

輸出:

參考: https://www.php.net/manual/en/function.imageaffine.php



相關用法


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