Open In App

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: 



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
// 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
// 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

Article Tags :