Jai’s Weblog – Tech, Security & Fun…

Tech, Security & Fun…

  • Jaibeer Malik

    Jaibeer Malik
  • View Jaibeer Malik's profile on LinkedIn
  • Subscribe

  • Feedburner

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 32 other followers

  • Archives

  • Categories

  • Stats

    • 412,782
  • Live Traffic

  • Advertisements

ImageMagick: Choosing right image format for image manipulation

Posted by Jai on October 17, 2012

ImageMagick is indeed very handy for different image manipulations for different purposes. In this post we will see how choosing the right image format is necessary while doing image manipulation based on your different business or usage scenarios.

Supported Formats

ImageMagick supports 100 plus image formats, detailing out at Formats.

Based on your environment settings and handlers/converters installed on your system, you can see what formats are supported on your system.

 identify -list format

Quality Parameter

The “quality” parameter in the command line option controls the compression level for JPEG/MIFF/PNG formats.

For the JPEG and MPEG image formats, quality is 1 (lowest image quality and highest compression) to 100 (best quality but least effective compression). The default is to use the estimated quality of your input image if it can be determined, otherwise 92. When the quality is greater than 90, then the chroma channels are not downsampled.

The quality parameter helps you to control the compression level, which directly affects the size and quality of the output image. You need to see what compression level and processing time requirements you have in your case.

convert portrait.jpg -gamma .45455 -resize 25% -gamma 2.2 \
-quality 92 passport.jpg

For example, if you need to process the images for preview or thumbnail purposes you can have lower compression level or quality of thumbnails, faster processing and if you are processing the images for actual printing you may prefer to have better quality of image which may result in slow processing.

Based on your requirements, you may choose to have different quality setting on intermediate image manipulation step and final image.

Lossless Compression

Lossless compression allows the exact original data to be reconstructed from the compressed data. PNG is one of such image formats.

The advantage of working with PNG images would be no or minimum data loss during image manipulations. But it comes with a cost of size and processing speed. The overhead of compression and decompression and control of quality of compression needs to be analyzed from case to case.

In case you need to apply multiple image manipulations on your image, you may choose to use PNG format for intermediate conversions and then JPG/JPEG as final format which will be transferred over net.

Bitmap Handling

You can also choose to work directly with the bitmap which is uncompressed data.

Handling uncompressed data comes with a cost of size and processing time. The bmp image file size is quite big and handling that big data file cause additional overhead and compromise on the processing time for image manipulation. This will lead to high quality and high processing time.

Size Limitation

The image size is critical parameter in processing time for an image manipulation using imagemagick. Higher the image size, depending on different image formats, BMP/PNG/JPG the processing time is different.

Applying image manipulation on original image file and on smaller size of same image (try re-sizing the image first to lower values) quite drastically effects the processing time.

You need to choose the correct size and processing time combination for your requirements.

Efficiency/Processing time

Processing time can be one of major criteria during image manipulation. For example, on website over net you may be generating previews based on different user selection paramters and processing time is very important for you.

Explore different additional command line options for efficiency, eg. “strip” can help to remove unwanted information from the image.

convert test.jpg -strip -quality 92 final.jpg

Try, additional attribute “thumbnail” which is faster than the resize operation on the image,

convert test.jpg -thumbnail 132x44! final.jpg

One of approach you can choose for is to resize your original image to lower size, apply image manipulation to higher quality and then convert the image to be transferred over net as JPG/JPEG. You still need to play around with resize and compression level for the manipulation to decide on size and processing time for the final output.


Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: