如何使用 PHP 中的 imagegetclip() 函式來獲取剪貼矩形?


imagegetclip() 是一個內建 PHP 函式,用於獲取剪貼矩形。用於獲取當前剪貼矩形,在此區域之外不會繪製任何畫素。

語法

array imagegetclip(resource $image)

引數

imagegetclip() 僅接受一個引數,$image。它包含由imagecreatetruecolor() 等影像建立函式返回的影像資源。

返回型別

imagegetclip() 返回一個索引陣列,其中包含剪貼矩形 x、y 左上角以及 x、y 左下角的座標。

示例 1

<?php
   $img = imagecreate(200, 200);

   //set the image clip.
   imagesetclip($img, 20,20, 90,90);
   print_r(imagegetclip($img));
?>

輸出

Array (
   [0] => 20
   [1] => 20
   [2] => 90
   [3] => 90
)

示例 2

<?php
   // load an image from the local drive folder
   $img = imagecreatefrompng('C:\xampp\htdocs\Images\img34.png');
   print("<pre>".print_r(imagegetclip($img),true)."<pre>");
?>

輸出

Array
(
   [0] => 0
   [1] => 0
   [2] => 611
   [3] => 395
)

更新於: 2021-08-09

76 次瀏覽

開啟你的職業生涯

完成課程獲得認證

開始學習
廣告