如何在 PHP 中使用 imagegetclip() 函数获取剪切矩形?

imagegetclip()是一个内置的 PHP 函数,用于获取剪切矩形。它用于检索当前的剪切矩形,即不会绘制超出该区域的像素。

语法

array imagegetclip(resource $image)

参数

imagegetclip()只接受一个参数$image。它保存由图像创建函数之一返回的图像资源,例如imagecreatetruecolor().

返回类型

imagegetclip() 返回一个索引数组,其中包含裁剪矩形 x, y 左上角和 x, y 左下角的坐标。

示例 1

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

   //设置图像剪辑。
   imagesetclip($img, 20,20, 90,90);
   print_r(imagegetclip($img));
?>
输出结果
Array (
   [0] => 20
   [1] => 20
   [2] => 90
   [3] => 90
)

示例 2

<?php
   // 从本地驱动器文件夹加载图像
   $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
)

猜你喜欢