Thursday, October 9, 2025
HomeLanguagesPHP | imageaffinematrixget() function

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32346 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6714 POSTS0 COMMENTS
Nicole Veronica
11877 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11940 POSTS0 COMMENTS
Shaida Kate Naidoo
6835 POSTS0 COMMENTS
Ted Musemwa
7094 POSTS0 COMMENTS
Thapelo Manthata
6789 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS