Cover Image for Imagick transposeImage() Function in PHP
161 views

Imagick transposeImage() Function in PHP

In PHP, Imagick::transposeImage() is a method of the Imagick class, which is part of the Imagick extension. The Imagick extension is a powerful PHP library that allows you to manipulate images using the ImageMagick software.

The transposeImage() method is used to transpose an image, which means it flips the image over its top-left to bottom-right diagonal. In other words, the rows of pixels become columns, and the columns become rows, effectively rotating the image 90 degrees clockwise.

Here’s the syntax of the transposeImage() method:

public Imagick::transposeImage()

Return value:

  • The method returns true on success.

Example:

// Create a new Imagick object and read an image file
$imagick = new Imagick('input.jpg');

// Transpose the image (rotate 90 degrees clockwise)
$imagick->transposeImage();

// Set the output image format to JPEG
$imagick->setImageFormat('jpeg');

// Output the modified image to the browser
header('Content-Type: image/jpeg');
echo $imagick;

In this example, we create an Imagick object and load an image file named input.jpg. We then use the transposeImage() method to transpose the image, effectively rotating it 90 degrees clockwise. The modified image is then output to the browser.

The transposeImage() method can be used to achieve different transformations in combination with other rotation and flipping functions provided by Imagick.

Please note that to use the Imagick class and its methods, you need to have the Imagick extension installed and enabled on your PHP server. Additionally, you should have the ImageMagick software installed on the server for the Imagick extension to work properly.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS