Javatpoint Logo
Javatpoint Logo

Imagick rotateImage() Function

The Imagick::rotateImage() method in PHP is used to rotate an image by a certain angle and fill the empty regions with a specified colour.

Syntax

The following parameters are accepted by this function, as mentioned above and described below:

$background: This option is used to change the image's background colour. This data type can be either string or float.

$degrees: The angle at which the image is rotated is set with this argument. The angle of rotation is read as clockwise.

Return Value

The return value of this function is a Boolean value depending upon the success and failure of the function. The return type of this function will be a true value if the rotation of the input image is successful. On the other hand, if the rotation of the input image is unsuccessful the return type of this function will be changed to false.

Code

Output:

Imagick rotateImage() Function

The code that is written above will result in the rotation of the input image that is passed from the image path variable will have the absolute path of the image on which we want to do rotation and the colour and angle are the two additional parameters that we have passed to the rotate Image function that will actually perform the rotation function.

Let us see some other practical examples of the Imagick rotateImage() Function in PHP.

Code

Output:

1 = 359
90 = 270
270 = 90
359 = 1
360 = 0

Some transformations, such as Imagick::rotateImage(), can alter the "image page," which is the working area within the picture you're working on. After then, be careful with future changes because the picture page will be different depending on the new image sizes. If you use Imagic::cropImage() after rotation, for example, you must set the image page correctly, or your crop will be based on incorrect coordinates (depending on rotation angle, resulting image size may vary).

Code

Output:

Imagick rotateImage() Function

After performing the rotation of an image with the use of rotate Image function in PHP there are some complications that the user can face one of that complications is using the cropped image after performing the rotation operation the user should be more cautious about performing the cropping and other such operations the above-written code shows such one scenario where the crop operation is performed after the successful rotate image operation on the input image, the input image, in this case, is rotated with 45 degrees of angle which is passed as a parameter to the rotate Image function.

Therefore, in this article, we have gone through the rotate Image function of the PHP with the help of which function we can easily rotate an image to our desired angle bypassing that rotation angle value as a parameter to the rotate Image function.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA