如何使用 PHP 中的 imagegetclip() 函数获取剪辑矩形?
phpserver side programmingprogramming
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 )