2Hats . 3 minutes
September 22, 2016

Easy image manipulation with Imagick PHP Extension

When it comes to uploading photos, image cropping/resizing in a website, php GD library comes in handy. But if we need to add more complicated image processing functionalities to our website like merging multiple images, rotating or color processings like photoshop, php ImageMagick library helps to do such processes more simple with better quality output than php GD library.

Availability

The GD library is included by default since PHP 4.3 and available in most server environments. ImageMagick may not always be available and some of the hosting companies don’t include it in their server.

We can check the availability by using following code.

We can integrate it or enable it by few simple steps. Detail information on integrate/enable imagemagick library is available on following link. http://php.net/manual/en/book.imagick.php

Supported file types

Php GD library only support JPG, PNG, GIF, WBMP, WebP, XBM and XPM files. When it comes to ImageMagick, php GD library is not much comparing to over a hundred file types handled by the ImageMagick library.

How to use

Create image with transparent background

We can create an image with transparent background in imagick by using following code.

Create image from file

We can create an image from an image file using following code

Create image from url

We can also create an image from url by using following code

Resize image

As compared to php GD library, resizing an image is pretty simple in imagick library. We can resize any image by using following code

Crop image

We can use ‘cropImage’ function to crop an image in required dimensions.

Rotate image

Rotating an image is also can be done by a single line of code.

Convert image

We can convert any imagick image object to required format very quickly by using following lines of code.

Save image

Save final image to a file after editing can be done by using following code

Merge images

Merging multiple images in imagIck can be done using following code.

Other useful functions

So many other handy image functions are available in imagick library. Some other main functions are listed below.

//Get the size associated with the Imagick object

//Get dimensions of the image

//Get format of ImageMagick object

Hope this helps someone working with Imagick.

blog
Greetings! I'm Aneesh Sreedharan, CEO of 2Hats Logic Solutions. At 2Hats Logic Solutions, we are dedicated to providing technical expertise and resolving your concerns in the world of technology. Our blog page serves as a resource where we share insights and experiences, offering valuable perspectives on your queries.
Aneesh ceo
Aneesh Sreedharan
Founder & CEO, 2Hats Logic Solutions
Subscribe to our Newsletter
Aneesh ceo

    Stay In The Loop!

    Subscribe to our newsletter and learn about the latest digital trends.