PHP | imageaffine() Function
Last Updated :
28 Jan, 2020
Improve
The imageaffine() function is an inbuilt function in PHP which is used to get an image containing the affine transformed src image using an optional clipping area. Affine is a geometric transformation operation involving MATRICES.
Syntax:
php
Output:
Program 2:
php
Output:
Reference: https://www.php.net/manual/en/function.imageaffine.php
resource imageaffine( resource $image, array $affine, array $clip )Parameters: This function accept three parameters as mentioned above and described below:
- $image: It specifies the image resource.
- $affine: It specifies the array with keys 0 to 5.
- $clip: It specifies the area to be clipped.
<?php
// Create a image from url
$im = imagecreatefrompng(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
// Affine the image
$newimage = imageaffine($im, [ -1.3, 0, 0, -0.7, 0, 0 ]);
// Output the image
header('Content-Type: image/png');
imagepng($newimage);
?>

<?php
// Create a image from url
$im = imagecreatefrompng(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
$clipped = [
'x' => 0,
'y' => 0,
'width' => 200,
'height' => 200,
];
// Affine the image
$newimage = imageaffine($im, [-1, 0, 0, sin(4), 0, 0], $clipped);
// Output the image
header('Content-Type: image/png');
imagepng($newimage);
?>
