如何使用 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 次浏览

开启你的职业生涯

完成课程获得认证

开始学习
广告
© . All rights reserved.