• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

imagemagick for image optimization

by admin

Last time we were talked about jpegoptim, jpegtran, optipng and pngcrush for image optimization. Today, We will review ImageMagick. Use ImageMagick® to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats (over 200) including PNG, JPEG, GIF, HEIC, TIFF, DPX, EXR, WebP, Postscript, PDF, and SVG. Use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.

Installation of imagemagick

On Debian, this utility is included in packages:

# apt-get install imagemagick

Example of imagemagick usage

GIF and PNG are lossless formats, in that the compression process does not make any visual modification to the images. For still images, PNG achieves better compression ratio with better visual quality. For animated images, consider using video element instead of a GIF, to achieve better compression.

  • Always convert GIF to PNG unless the original is animated or tiny (less than a few hundred bytes).
  • For both GIF and PNG, remove alpha channel if all of the pixels are opaque.

For example, you can use convert binary to optimize your GIF and PNG images with the following command (parameters inside brackets are optional):

$ convert INPUT.gif_or_png -strip [-resize WxH] [-alpha Remove] OUTPUT.png
cuppa.png (1,763 Bytes)

cuppa.png (1,763 Bytes)

$ convert cuppa.png -strip cuppa_converted.png
cuppa_converted.png (856 Bytes)

cuppa_converted.png (856 Bytes)

JPEG is a lossy format. The compression process removes visual details of the image, but the compression ratio can be 10x larger than GIF or PNG.

  • Reduce quality to 85 if it was higher. With quality larger than 85, the image becomes larger quickly, while the visual improvement is little.
  • Reduce Chroma sampling to 4:2:0, because the human visual system is less sensitive to colors as compared to luminance.
  • Use progressive format for images over 10k bytes. Progressive JPEG usually has a higher compression ratio than baseline JPEG for large images, and has the benefits of progressively rendering.
  • Use grayscale color space if the image is black and white.

For example, you can use convert binary to optimize your JPEG images with the following command (parameters inside brackets are optional):

$ convert INPUT.jpg -sampling-factor 4:2:0 -strip [-resize WxH] [-quality N] [-interlace JPEG] [-colorspace Gray/sRGB] OUTPUT.jpg
puzzle.jpg (13,501 Bytes)

puzzle.jpg (13,501 Bytes)

$ convert puzzle.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace sRGB puzzle_converted.jpg

Filed Under: Linux

Some more articles you might also be interested in …

  1. make Command Examples in Linux
  2. po4a-gettextize: command not found
  3. How to Read Audit Log in Linux
  4. What are the Network Bonding Modes In CentOS / RHEL
  5. bspc: command not found
  6. goldeneye.py Command Examples in Linux
  7. service Command Examples in Linux
  8. check-support-status: Command Examples in Linux
  9. How to set “max_report_luns” and “max_luns” on CentOS/RHEL 7 to scan more than 16,383 LUNs
  10. Linux / UNIX : Examples of find command to find files with specific sets of permissions

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright