文字

imageaffine

(PHP 5 >= 5.5.0, PHP 7)

imageaffine返回经过仿射变换后的图像,剪切区域可选

说明

resource imageaffine ( resource $image , array $affine [, array $clip ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

image

由图象创建函数(例如 imagecreatetruecolor() )返回的图象资源。

affine

数组,其中键为 0 至 5 的数字。

clip

数组,其中键为 "x","y","width" 和 "height"。

返回值

成功则返回仿射变换后的图像, 或者在失败时返回 FALSE .

用户评论:

[#1] abc at ed48 dot com [2013-12-22 17:52:01]

Here is an example, which performs a specific processing, every time it is executed:

<?php 

if (!function_exists('imageaffine')) 

echo 
'FUNCTION NOT DEFINED IN THIS VERSION OF PHP'
exit; 


$base_img 'affine.png'

$tgt_img1 'triangle1.png'

$tgt_img2 'triangle2.png'

$arr_affine = [ 
10010], 
1001150], 
1.2000.60], 
[ -
1.200, -0.60], 
12010], 
21010], 
cos(15), sin(15), -sin(15), cos(15), 0], 
cos(15), -sin(15), sin(15), cos(15), 0
];

$RSR_base imagecreatetruecolor(400300); 
$w imagesx($RSR_base); 
$h imagesy($RSR_base); 

$arr_clip = [ 'x' => 0'y' => 0'width' => $w'height' => $h ]; 

$fillcolor imagecolorallocate($RSR_base000); 

imagefill($RSR_base10,10$fillcolor); 

imagepng($RSR_base$base_img); 

$drawcolor imagecolorallocate($RSR_base25500);  

$triangle = [ 505050150200150 ]; 
$points 3

imageantialias($RSR_base1); 

$drawtriangle imagefilledpolygon($RSR_base$triangle$points$drawcolor);

imagepng($RSR_base$tgt_img1);

$select mt_rand(07); 

$RSRaff2 imageaffine($RSR_base$arr_affine[$select], $arr_clip); 

imagepng($RSRaff2$tgt_img29); 

?>
 

SUPPORT IMAGE<br><br> 
<img src=" <?php echo $base_img?> " alt="*" /><br><br> 

BASE IMAGE<br><br> 
<img src=" <?php echo $tgt_img1?> " alt="*" /><br><br> 

RESULT IMAGE<br><br> 
<img src=" <?php echo $tgt_img2?> " alt="*" />

[#2] abc at ed48 dot com [2013-12-22 17:17:08]

correcting:

c ) SCALE,

         $affine = [ M, 0, N, 1, 0, 0 ];

         equations remapping,
         
         x' = Mx + 0y + 0 = Mx
         
         y' = 0x + Ny = 0 = Ny
         
         Each point will stretch or compress its path, horizontally or vertically, according M and N; negative or positive values.

[#3] abc at ed48 dot com [2013-12-22 16:10:56]

AFFINE is a geometric transformation operation involving MATRICES, covering both, 2D and 3D environment.
Transformations are often used in linear algebra and computer graphics.

In geometric transformations of images, the pixel coordinate is mapped.

This means that, each pixel is localized by two coordinates, in the rectangular domain of the image.
Without going into more details about pixel mapping, let's get to what really matters: the AFFINE transformations.
There are several classes of pixel mapping, one is called "affine".
Affine transformations include: scaling, rotation, shearing and translation.

PHP 5.5.0+, like "libart", uses ARRAYS of six floating-point elements to do the job.

The AFFINE ARRAY, is defined like, 

         $affine = [ a0, a1, b0, b1, a2, b2 ];
 
 where, 
 a0, a1, b0, b1, a2, b2 are floating-point values.
 
 represented by equations,
 
 x' = a0x + a1y + a2
 
 y' = b0x + b1y + b2
 
a ) IDENTITY, no change made in the path of points,

         $affine = [ 1, 0, 0, 1, 0, 0 ];
 
 equations remapping,
 
 x' = 1x + 0y + 0 = x
 
 y' = 0x + 1y = 0 = y
 
b ) TRANSLATION,

         $affine = [ 1, 0, 0, 1, H, V ];

 equations remapping,
 
 x' = 1x + 0y + H = x + H
 
 y' = 0x + 1y = V = y + V
 
 Each point is moved H units horizontaly and V units verticaly.
 
c ) SCALE,

         $affine = [ i, 0, j, 1, 0, 0 ];

 equations remapping,
 
 x' = Mx + 0y + 0 = Mx
 
 y' = 0x + Ny = 0 = Ny
 
 Each point will stretch or compress its path, horizontally or vertically, according M and N; negative or positive values.
 
d ) SHEARING, parallel to x axis,

         $affine = [ 1, K, 0, 1, 0, 0 ];

 equations remapping,
 
 x' = 1x + Ky + 0 = x + Ky
 
 y' = 0x + 1y = 0 = y
 
    SHEARING, parallel to y axis,

         $affine = [ K, 0, 0, 1, 0, 0 ];

 equations remapping,
 
 x' = 1x + 0y + 0 = x
 
 y' = Kx + 1y = 0 = y + Kx
 
e ) ROTATION, clockwise,

         $affine = [ cos ?, sin ?, -sin ?, cos ?, 0, 0 ];

 equations remapping,
 
 x' =  x cos ? + y sin ? + 0 = x cos ? + y sin ?
 
 y' = -x sin ? + y cos ? = 0 = y cos ? - x sin ?
 
    ROTATION, conterclockwise,

         $affine = [ cos ?, -sin ?, sin ?, cos ?, 0, 0 ];

 equations remapping,
 
 x' =  x cos ? - y sin ? + 0 = x cos ? - y sin ?
 
 y' = x sin ? + y cos ? = 0 = y sin ? - x cos ?

上一篇: 下一篇: