首页 话题 小组 问答 好文 用户 我的社区 域名交易 唠叨

[函数]imageaffinematrixget()函数—用法及示例

发布于 2025-04-27 14:11:12
0
25

函数名:imageaffinematrixget()

适用版本:PHP 5 >= 5.5.0, PHP 7

用法:imageaffinematrixget() 函数返回一个包含图像的仿射变换矩阵的数组。

语法:array imageaffinematrixget ( int $type [, mixed $options ] )

参数:

  • type:指定返回的矩阵类型,可以是以下常量之一:
    • IMG_AFFINE_TRANSLATE:平移变换
    • IMG_AFFINE_SCALE:缩放变换
    • IMG_AFFINE_ROTATE:旋转变换
    • IMG_AFFINE_SHEAR_HORIZONTAL:水平剪切变换
    • IMG_AFFINE_SHEAR_VERTICAL:垂直剪切变换
  • options:可选参数,根据不同的变换类型,可以传递额外的参数。

返回值:返回一个包含图像的仿射变换矩阵的数组,如果出错则返回 false。

示例:

// 创建一个 200x200 的白色背景图像
$image = imagecreatetruecolor(200, 200);
$white = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $white);

// 获取平移变换矩阵
$matrix = imageaffinematrixget(IMG_AFFINE_TRANSLATE, array('x' => 50, 'y' => 50));

// 应用平移变换矩阵
imageaffine($image, $matrix);

// 保存图像到文件
imagepng($image, 'translated_image.png');
imagedestroy($image);

在上面的示例中,我们创建了一个 200x200 的白色背景图像,并使用 imageaffinematrixget() 函数获取了一个平移变换矩阵,将图像平移了 50 个像素的距离。然后,我们使用 imageaffine() 函数应用了该变换矩阵,最后将图像保存到了文件 "translated_image.png" 中。

评论
一个月内的热帖推荐
啊龙
Lv.1普通用户

9545

帖子

31

小组

3242

积分

赞助商广告
站长交流