Imagemagick: Difference between revisions

From miki
Jump to navigation Jump to search
Line 1: Line 1:
== Reference ==
== Reference ==
* [http://www.imagemagick.org/script/command-line-options.php Imagemagick command-line options]
* [http://www.imagemagick.org/script/command-line-options.php Imagemagick command-line options]
* [http://www.fmwconcepts.com/imagemagick/index.php '''Fred's ImageMagick Scripts'''] — An impressive set of scripts.


== Howto ==
== Howto ==

Revision as of 10:57, 15 April 2018

Reference

Howto

Image resize

convert input.jpg -resize 500x500 output.jpg                          # Resize to fit in 500x500 max. Final image is not necessarily 500x500.
convert input.jpg -resize 500x500 -background black -compose Copy \ 
  -gravity center -extent 500x500 output.jpg                          # Resize, and if necessary center image and pad with black background
convert input.jpg -filter cubic  -resize 500x500 output.jpg           # Set resize filter. 'convert -list-filter' to get a list 
convert input.jpg -filter cubic  -resize 500x500^ output.jpg          # Resize to fix outside 500x500, preserving aspect ratio.

Get image info

convert -format "%f %w %h" sand.jpg info:
identify -format "%f %w %h" sand.jpg                                   # Same but shorter
identify sand.jpg -format "%f %w %h"                                   # WRONG - format string must come before because params are processed sequentially
read -r file width height <<< $(identify -format "%f %w %h" sand.jpg)  # Set values in variables

Crop an image

convert IMG_0001.jpg -gravity Center -crop 1000x1000+0+0 +repage IMG_0001-resized.jpg  # Crop a 1000x1000 region around center. The '+0+0' are mandatory.

Convert to JPG

convert IMG_0001.png IMG_0001.jpg                # Convert with default quality
convert IMG_0001.png -quality 96 IMG_0001.jpg    # Specify JPG quality

Blur an image

convert IMG_0001.jpg -gaussian-blur 5x2 IMG_0001-blur.jpg    # Similar to Gimp gaussian blur 5x5 px
convert IMG_0001.jpg -gaussian-blur 5x2 -filter cubic -resize 1000x1000^ -gravity Center -crop 1000x1000+0+0 +repage -quality 96 IMG_0001-resized.jpg

Get pixel color of an image

Use pixel::

convert image.png -format '%[pixel:p{545,276}]' info:-

Now say we want to pick the pixel color of a sequence of images, but only keep those information when the color changes in the sequence:

last=""; for f in png/*.png; do color=$(convert $f -format '%[pixel:p{545,276}]' info:-); if ! [ "$last" = "$color" ]; then echo "$f; $color"; last=$color; fi; done > banner_bg_colors.txt