Using ImageMagick

ImageMagick is a software suite that can be used to manipulate images. In order to use it with InMotion Hosting web hosting servers, you would need to use code such as PHP or execute a command in SSH. The following article will describe how to find and use ImageMagick commands to resize an image and give you some brief examples. We will also provide links for more comprehensive information on the many functions available through ImageMagick.

How is ImageMagick accessed?

By default, ImageMagick is installed on InMotion Hosting servers. However, it can only be accessed through the command line, a cron job or PHP code on a web page. The path for the command line options would look like this:

  • /usr/bin/convert
  • /usr/bin/mogrify

ImageMagick has many modules that can be loaded, but for the purposes of InMotion's hosting servers, the main commands available are Convert and Mogrify. These commands can be used through PHP using a native extension called Imagick. For more information, please see the Imagick class in the PHP documentation.

Using ImageMagick

ImageMagick can be used through SSH and PHP. The following examples are executed in SSH to resize images like the ones below. Each example uses the convert command. By default, the convert command maintains the aspect ratio of the image by.

Using Convert

When you use the commands below, the apect ratio of the image is not changed. This means that if you convert an image that is originally 320x220 pixels to 64 x 64 pixels (as per the examples below), the actual size will be 64 x 44 pixels, because it shrinks to the smallest dimension while maintaining the aspect ratio. For more information, please see aspect ratio below.

VPS and Dedicated servers with SSH access

convert larger-image.png -resize 64x64 smaller-image.png

Cron job command for shared servers with no SSH access

/usr/bin/convert public_html/larger-image.png -resize 64x64 public_html/smaller-image.png

PHP command for shared servers with no SSH access

exec('/usr/bin/convert /home/USERNAME/public_html/larger-image.png -resize 64x64 /home/USERNAME/public_html/smaller_image.jpg');

You will need to replace USERNAME with the actual username of the account. You will also need to make sure that the folder where the converted image is being saved has the proper write permissions.

Using Mogrify

The mogrify command can be used in place of convert to resize an image with the main difference being that it modifies the original file. For more documentation on using mogrify, please go here. Like convert, the mogrify command maintains the aspect ratio of the image by default.

VPS and Dedicated servers with SSH access

mogrify -resize 64x64 original-image.png

Cron job for shared servers with no SSH access

/usr/bin/mogrify -resize 64x64 public_html/orignal-image.png

PHP script command for shared servers with no SSH access

exec('/usr/bin/mogrify -resize 64x64' /home/USERNAME/public_html/original-image.png );

You will need to replace USERNAME with the actual username of the account. You will also need to make sure that the folder where the converted image is being saved has the proper write permissions.

Understanding Image Aspect Ratio

Using convert or mogrify commands that are listed above will change the size of the image while automatically maintaining the aspect ratio of the image. The simplest way to understand this concept is to imagine taking an image and shrinking it down without causing any distortion of the image. The commands above use a square image of 64 x 64 pixels. If it were to shrunk to 32 x 32 pixels, it will maintain its aspect ratio and not show any distortion because the image remains square. However, if it were to be shrunk to 32 x 20 pixels, then the image is no longer square and the aspect ratio would be different causing distortion. Here's an example using the picture of a cat:

Original ImageAspect ratio maintained Aspect ratio changed
Original Cat Image Aspect ratio maintained Aspect ratio changed

You can see the differences in the images of the cat above. If you wish to force a change in aspect ratio, then the main difference in the command will be to add an "!" after the declared size for the image. Here's an example:

convert original-image.png -resize 64x64/! smaller-image.png

mogrify -resize 64x64/! original-image.png

Further info on ImageMagick

ImageMagick is a complex suite of tools that you can use to create and modify images in many formats. The information that we have provided here is merely a snapshot of its vast capabilities. The options available on InMotion's shared server accounts primarily involve the convert and mogrify commands, but there are many other modules and processing options that you can load if you are using ImageMagick on a VPS or dedicated server account.

When you are using ImageMagick remember that the commands you use may possibly process a large number of images. This can severely affect the resources of your server. For more information on resource issues, please see Excessive CPU Processing. If you must process in large numbers, do them in several groups and during off-peak hours. Contact InMotion Hosting's technical support team if you require further information. For further information see the ImageMagick.org website for further tutorials and much more documentation.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

News / Announcements

WordPress wp-login.php brute force attack
Updated 2014-07-17 06:43 pm EST
Hits: 200935

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!