PHP | imageaffinematrixget() function

The imageaffinematrixget() function is an inbuilt function in PHP which is used to get an affine transformation matrix. Affine is a geometric transformation operation involving matrices, often used in linear algebra and computer graphics.

Syntax:

array imageaffinematrixget( int $type, mixed $options )

Parameters:This function accepts two parameters as mentioned above and described below:



  • $type: It specifies an integer corresponding to one of IMG_AFFINE constants.
    List of all IMG_AFFINE constants are given below:

    • IMG_AFFINE_TRANSLATE (0)
    • IMG_AFFINE_SCALE (1)
    • IMG_AFFINE_ROTATE (2)
    • IMG_AFFINE_SHEAR_HORIZONTAL (3)
    • IMG_AFFINE_SHEAR_VERTICAL (4)
  • $options: It specifies the options to be converted into array which can be array or float.

Return Value: This function retruns an affine transformation matrix (an array with keys 0 to 5 and float values) or FALSE on failure.

Below given programs illustrate the imageaffinematrixget() function in PHP:
Program 1 (Creating from a array):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// Create an array
$arr = array('x' => 5, 'y' => 8);
  
// Get the image affine matrix
$matrix = imageaffinematrixget(IMG_AFFINE_TRANSLATE, $arr);
  
// Output the matrix
print("<pre>".print_r($matrix, true)."</pre>");
?>

chevron_right


Output:

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

Program 2 (Creating from an angle):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// Create an angle
$angle = 300;
  
// Get the image affine matrix
$matrix = imageaffinematrixget(IMG_AFFINE_SHEAR_HORIZONTAL, $angle);
  
// Output the matrix
print("<pre>".print_r($matrix, true)."</pre>");
?>

chevron_right


Output:

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

Reference: https://www.php.net/manual/en/function.imageaffinematrixget.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.