HomeLanguagesPHP | imageaffine() Function

PHP | imageaffine() Function

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:

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.

Return Value: This function returns affined image resource on success or FALSE on failure.

Exceptions: This function throws Exception on error.

Below given programs illustrate the imageaffine() function in PHP:

Program 1:




<?php
  
// Create a image from url
$im = imagecreatefrompng(
  
// Affine the image
$newimage = imageaffine($im, [ -1.3, 0, 0, -0.7, 0, 0 ]);
  
// Output the image
header('Content-Type: image/png');
imagepng($newimage);
?>


Output:

Program 2:




<?php
  
// Create a image from url
$im = imagecreatefrompng(
  
$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);
?>


Output:

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

RELATED ARTICLES

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS