imageaffinematrixget 


gd apg

RETURNS an affine transformation matrix.





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.


If
$type = IMG_AFFINE_TRANSLATE
or
$type = IMG_AFFINE_SCALE,
$options has to be an ARRAY with keys x and y, both having FLOAT values.


If
$type = IMG_AFFINE_ROTATE, $type = IMG_AFFINE_SHEAR_HORIZONTAL
or
$type = IMG_AFFINE_SHEAR_VERTICAL,
$options has to be a float specifying the angle.


This function returns FALSE on failure.



<?php

array|false imageaffinematrixget int $type, array|float $options )

where,

$type One of the IMG_AFFINE_constants
            
SEE the below TABLE )

$options An ARRAY with keys x and y
                                 
both having FLOAT values
 
?>
 

  $type   


One of the IMG_AFFINE_* constants.

VALUE CONSTANT
0 IMG_AFFINE_TRANSLATE
1 IMG_AFFINE_SCALE
2 IMG_AFFINE_ROTATE
3 IMG_AFFINE_SHEAR_HORIZONTAL
4 IMG_AFFINE_SHEAR_VERTICAL
ed48


  $options   


Depending on the values entered in $type may be expressed as FLOAT values.



  1 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$img_base 'png/PNG 087 01.png';

$img_tgt 'png/PNG 087 01 imageaffinematrixget ';

$arr1 = [ 01234.5820];

?>

EXISTING IMAGE<br><br>
<img src="<?php echo $img_base?>
alt="<?php echo $img_base?>"><br><br>

<?php
$id_aff0 
imagecreatefrompng($img_base);

foreach(
$arr1 as $a1)
{
$arr_at 
imageaffinematrixget(IMG_AFFINE_SHEAR_VERTICAL$a1);

$id_aff imageaffine($id_aff0$arr_at);

imagepng($id_aff$img_tgt $a1 '.png'9);

echo 
'<br><br>RESULTING IMAGE ( ' $a1 ' )<br><br>';

print_r($arr_at);

echo 
'<br><br><img src="' $img_tgt $a1 '.png' 
'"alt="' .  $a1 '"><br><br>';
}

?> 

 RESULT   


EXISTING IMAGE

apr PNG 087 01.png


IMG_AFFINE_SHEAR_VERTICAL



RESULTING IMAGE ( 0 )

Array
(
[0] => 1
[1] => 0
[2] => 0
[3] => 1
[4] => 0
[5] => 0
)


apr 0



RESULTING IMAGE ( 1 )

Array
(
[0] => 1
[1] => 0.017455064928218
[2] => 0
[3] => 1
[4] => 0
[5] => 0
)


apr 1



RESULTING IMAGE ( 2 )

Array
(
[0] => 1
[1] => 0.034920769491748
[2] => 0
[3] => 1
[4] => 0
[5] => 0
)


apr 2



RESULTING IMAGE ( 3 )

Array
(
[0] => 1
[1] => 0.052407779283041
[2] => 0
[3] => 1
[4] => 0
[5] => 0
)


apr 3



RESULTING IMAGE ( 4.58 )

Array
(
[0] => 1
[1] => 0.080106773937536
[2] => 0
[3] => 1
[4] => 0
[5] => 0
)


apr 4.58



RESULTING IMAGE ( 20 )

Array
(
[0] => 1
[1] => 0.3639702342662
[2] => 0
[3] => 1
[4] => 0
[5] => 0
)


apr 20

  2 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$img_base 'png/PNG 087 02.png';

$img_tgt 'png/PNG 087 02 imageaffinematrixget ';

$arr1 = [ 01234.5820];

?>

EXISTING IMAGE<br><br>
<img src="<?php echo $img_base?>
alt="<?php echo $img_base?>"><br><br>

<?php
$id_aff0 
imagecreatefrompng($img_base);

foreach(
$arr1 as $a1)
{
$arr_at 
imageaffinematrixget(IMG_AFFINE_SHEAR_HORIZONTAL$a1);

$id_aff imageaffine($id_aff0$arr_at);

imagepng($id_aff$img_tgt $a1 '.png'9);

echo 
'<br><br>RESULTING IMAGE ( ' $a1 ' )<br><br>';

print_r($arr_at);

echo 
'<br><br><img src="' $img_tgt $a1 '.png' 
'"alt="' .  $a1 '"><br><br>';
}

?>


 RESULT   

EXISTING IMAGE

apr png/PNG 087 02.png


IMG_AFFINE_SHEAR_HORIZONTAL



RESULTING IMAGE ( 0 )

Array
(
[0] => 1
[1] => 0
[2] => 0
[3] => 1
[4] => 0
[5] => 0
)


apr 0



RESULTING IMAGE ( 1 )

Array
(
[0] => 1
[1] => 0
[2] => 0.017455064928218
[3] => 1
[4] => 0
[5] => 0
)


apr 1



RESULTING IMAGE ( 2 )

Array
(
[0] => 1
[1] => 0
[2] => 0.034920769491748
[3] => 1
[4] => 0
[5] => 0
)


apr 2



RESULTING IMAGE ( 3 )

Array
(
[0] => 1
[1] => 0
[2] => 0.052407779283041
[3] => 1
[4] => 0
[5] => 0
)


apr 3



RESULTING IMAGE ( 4.58 )

Array
(
[0] => 1
[1] => 0
[2] => 0.080106773937536
[3] => 1
[4] => 0
[5] => 0
)


apr 4.58



RESULTING IMAGE ( 20 )

Array
(
[0] => 1
[1] => 0
[2] => 0.3639702342662
[3] => 1
[4] => 0
[5] => 0
)


apr 20

  3 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$img_base 'png/PNG 085 02.png';

$img_tgt 'png/PNG 085 03 imageaffinematrixget ';

$arr1 = [ 0102030, -40.5890];

?>

EXISTING IMAGE<br><br>
<img src="<?php echo $img_base?>
alt="<?php echo $img_base?>"><br><br>

<?php
$id_aff0 
imagecreatefrompng($img_base);

foreach(
$arr1 as $a1)
{
$arr_at 
imageaffinematrixget(IMG_AFFINE_ROTATE$a1);

$id_aff imageaffine($id_aff0$arr_at);

imagepng($id_aff$img_tgt $a1 '.png'9);

echo 
'<br><br>' basename($img_tgt);
echo 
" ( $a1 )<br><br>";

print_r($arr_at);

echo 
'<br><br><img src="' $img_tgt $a1 '.png' 
'"alt="' .  $a1 '"><br><br>';
}

?> 


 RESULT   

EXISTING IMAGE

apr PNG 085 02.png


IMG_AFFINE_ROTATE



PNG 085 03 imageaffinematrixget ( 0 )

Array ( [0] => 1 [1] => 0 [2] => -0 [3] => 1 [4] => 0 [5] => 0 )

apr 0



PNG 085 03 imageaffinematrixget ( 10 )

Array ( [0] => 0.98480775301221 [1] => 0.17364817766693 [2] => -0.17364817766693 [3] => 0.98480775301221 [4] => 0 [5] => 0 )

apr 10



PNG 085 03 imageaffinematrixget ( 20 )

Array ( [0] => 0.93969262078591 [1] => 0.34202014332567 [2] => -0.34202014332567 [3] => 0.93969262078591 [4] => 0 [5] => 0 )

apr 20



PNG 085 03 imageaffinematrixget ( 30 )

Array ( [0] => 0.86602540378444 [1] => 0.5 [2] => -0.5 [3] => 0.86602540378444 [4] => 0 [5] => 0 )

apr 30



PNG 085 03 imageaffinematrixget ( -40.58 )

Array ( [0] => 0.75949842412838 [1] => -0.65050914193922 [2] => 0.65050914193922 [3] => 0.75949842412838 [4] => 0 [5] => 0 )

apr -40.58



PNG 085 03 imageaffinematrixget ( 90 )

Array ( [0] => 6.1232339957368E-17 [1] => 1 [2] => -1 [3] => 6.1232339957368E-17 [4] => 0 [5] => 0 )

apr 90