Back to Top

How to crop an Image using Imagick in PHP

imagick crop image in PHP

In this quick post, I am going to explain how to crop the image in PHP using Imagick. Sometimes you want to crop an image and you might get confused what to do, which function to use so I personally suggest Imagick is good to use.I recently used Imagick on my site to crop the image and write to the folder.Imagick is used to crop images with any image formats such as JPEG, PNG, GIF, TIFF, BMP etc.

Before sometimes I was looking to resize the image after uploading it using PHP and to do it and I have used Imagick.

Introduction about Imagick

Imagick is the popular image generation library used to manipulate images with support of hundreds of image format.It provides excellent features, including image cropping and resizing. Imagick in PHP is a native PHP extension that provides a base class of ImageMagick library.Imagick also supports a command line execution.

Advantages of Imagick

  • Faster
  • require Less memory
  • Ease to use

Let’s check Imagick by cropping larger images to require dimension.Below is a sample code for image cropping using Imagick

function crop_image($image_name,$width=150,$height=150){
        /* Set image objects */
	$image = new Imagick($image_name);
	$crop_img = new Clone();


Install Imagick extension


In above function, Pass image_name, width and height of the image you want after cropping it.First of all, I have created the imagick object. then created a clone object and used thumbnailImage function to create thumb or crop the image using passed dimensions.Then create a cropped image using an existing image.

Read about: To create custom size thumbnail in WordPress

All set. 🙂 It works and solves your problems.I hope this function should work for you Good luck! If anyone has any problem, please comment here and I’ll try to help.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

Table layout using DIV tags

Posted on 6 years ago


GoTo statement in PHP

Posted on 7 years ago


What is Type Hinting in PHP5

Posted on 7 years ago


Hello world

Updated 1 week ago

Nick Carter

In depth Understanding of Laravel Core

Updated 2 months ago


ECMAScript 6 New Features – 2

Updated 1 year ago


The Reader’s Poll – August 2014

Posted on 4 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago