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


PHP imagesetclip()用法及代碼示例

imagesetclip()函數是PHP中的一個內置函數,用於設置當前的裁剪矩形,即超出該像素的區域。

用法:

bool imagesetclip( resource $im, int $x1, int $y1, int $x2, int $y2 )

參數:該函數接受上述和以下所述的五個參數:


  • $im:它指定要處理的圖像資源。
  • $x1:它指定左上角的x坐標。
  • $y1:它指定左上角的y坐標。
  • $x2:它指定右下角的x坐標。
  • $y2:它指定右下角的y坐標。

返回值:如果成功,則此函數返回TRUE;如果失敗,則返回FALSE。
下麵給出的程序說明了PHP程序1中的imagesetclip()函數:

<?php 
// Load the png image 
$image = imagecreatefrompng( 
    'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Set the clip 
imagesetclip($image, 0, 0, 40, 40); 
  
// Get the clip 
$clip = imagegetclip($image); 
print("<pre>".print_r($clip, true)."</pre>"); 
?>

輸出:

Array
(
    [0] => 0
    [1] => 0
    [2] => 40
    [3] => 40
)

程序2:

<?php 
// Load the png image 
$image = imagecreatefrompng( 
    'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Set the clip 
imagesetclip($image, 20, 20, 150, 150); 
  
// Create a line from upper left corner to (400, 400) 
// and you will see the line doesn't start from upper 
// left corner because it is clipped from (20, 20) 
$red = imagecolorallocate($image, 255, 0, 0); 
imageline($image, 0, 0, 400, 400, $red); 
  
// Output image to the browser 
header('Content-type:image/png'); 
imagepng($image); 
?>

輸出:

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



相關用法


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