Skip to content
Related Articles
Open in App
Not now

Related Articles

PHP | imageaffinematrixget() function

Improve Article
Save Article
  • Last Updated : 16 Jan, 2022
Improve Article
Save Article

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 returns 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): 

php




<?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>");
?>


Output: 

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

Program 2 (Creating from an angle): 

php




<?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>");
?>


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
Related Articles

Start Your Coding Journey Now!