English | 简体中文 | 繁體中文
查询

imageaffinematrixget()函数—用法及示例

「 返回一个包含图像的仿射变换矩阵的数组 」


函数名: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" 中。

补充纠错
上一个函数: imagealphablending()函数
下一个函数: imageaffinematrixconcat()函数
热门PHP函数
分享链接