How to convert, resize, and center image with ImageMagick

Cause (If you want to go to the method, skip this part):

I have one project that I have to add product to an e-commerce website and client sent me product images in PSD file and I need to convert it into JPG or PNG file to upload to the site. So the problem is, I don’t have Photoshop and (if I have) I don’t know how to use it. Hence, I find this solution, use ImageMagick to convert, resize, and center all images with ImageMagick instead of buying Photoshop to do it (or using GIMP).

Method part:

If what you want to do is same as mine, PSD file, PSD has layer, mostly you want to convert it at the first layer. But if you want to know how many layer in PSD file you can use command “identify” to check it out,


ImageMagick identify command

The result will look like this,

ImageMagick Identify result
ImageMagick Identify result

Now you will see size, type, and other detail of its.
And how to get to each layer of its file is, [number] for example, image.psd[0], or image.psd[1]

Next step is, get to the point “convert, resize, and center image”
You can use the command below to get what you want,

ImageMagick convert

Note: -extend value must larger than source image size that you get from identify

See the result and source file below,
You can see image’s aspect at the source file and what ImageMagick does. It’s awesome that you can done this job with single line of command in your Terminal/Command-line tool.

PSD source file
PSD source file
Converted image file by ImageMagick
Converted image file by ImageMagick

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s