ImageMagick: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
 
(21 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Manipulating images on the command-line with ImageMagick =
{{Software
|Website=http://www.imagemagick.org/
|License=Apache
|OS=Linux, Mac, iOS, Windows
|Media=Image
|Format=JPEG, PNG, GIF, TIFF
|Interface=Command-line interface,
|Wikipedia=http://en.wikipedia.org/wiki/Image_Magick
|Thumbnail=File:Imagemagick-logo.jpg
}}




[[Category: Software]]
ImageMagick is a suite of [[commandline]] tools for manipulating images. It's often called the "swiss army knife" of image tools. It is [[free software]].
== Links ==
* http://www.imagemagick.org/
* [http://www.imagemagick.org/Usage/ usage] tutorial
* Several commands use [http://www.imagemagick.org/script/command-line-processing.php#geometry geometry] specifications


== General ==
== General ==
Imagemagick provides a number of [[commandline]] tools, none of which are named imagemagick, but rather:
* convert: create/modify an image and save as a new file
* mogrify: makes changes to an image "in-place" (replacing the original -- use with caution!)
* montage: automated "poster" maker that creates a "thumbnail" image of a number of images (in a grid with variable spacing and options like showing the filename)
* identify: display information about an image
* display: show an image in a window (may not work on OS X, use the "open" command instead)


=== Checking if you have ImageMagick installed ===
== How to check if ImageMagick is installed ==
Type the name of one of the above commands in a terminal/shell, such as:
convert


Ubuntu generally comes with ImageMagick already installed. To check if ImageMagick is installed, you don't actually type ''imagemagick'', but rather one the several commands that are part of the package. For instance, try:
=== Installing ImageMagick ===
<source lang="text">
 
convert
In Linux, ImageMagick should either already be installed, or is available via whatever package manager the distribution supports. In Debian/Ubuntu:
</source>


sudo apt-get install imagemagick


=== Installing ImageMagick ===
or on mac ox, try:


<source lang="text">
brew install imagemagick
sudo apt-get install imagemagick
</source>


==== OS X ====
== Resizing A folder of Images with mogrify ==


Searching for "imagemagick OSX" should bring up some packages that have been pre-compiled for the various version of OS X.
DANGER: this replaces all the images in the current folder with thumbnails, so you'd make a copy first!


As of early 2013, [http://cactuslab.com/imagemagick/ this link] seems to be up to date.
mogrify -resize 320x240 *


=== Seeing what version of ImageMagick you have ===
=== Seeing what version of ImageMagick you have ===
Line 32: Line 57:
convert --version
convert --version
</source>
</source>


=== Creating new images (without changing any originals) ===
=== Creating new images (without changing any originals) ===
Line 62: Line 86:
display foo.png
display foo.png


=== Finding more examples of how to use ImageMagick ===
==pdfunite==


http://www.imagemagick.org/Usage/
From package: poppler-utils


== Cutting ==
== Cutting ==
Line 88: Line 112:
convert original.png -crop x64 bar%04d.png
convert original.png -crop x64 bar%04d.png
</source>
</source>


== Transforming ==
== Transforming ==
Line 124: Line 147:


Use montage.
Use montage.
Arrange the frames as tiles on new jpg files.
Geometry describes how big each image is resized to (640) and the spacing in between the tiles (+10+10).
%04d in the output filename means that the results are numbered starting from 0001 (0-padded to 4 places).
<source lang=bash>
montage -geometry '640x640>+10+10' -tile 1x3 /*.jpg test%04d.jpg
</source>


== Drawing ==
== Drawing ==

Latest revision as of 12:28, 10 January 2020

Website http://www.imagemagick.org/
License Apache
OS Linux, Mac, iOS, Windows
Media Image
Format JPEG, PNG, GIF, TIFF
Interface Command-line interface,
Wikipedia http://en.wikipedia.org/wiki/Image_Magick
Thumbnail
Imagemagick-logo.jpg

ImageMagick is a suite of commandline tools for manipulating images. It's often called the "swiss army knife" of image tools. It is free software.

Links

  • Several commands use geometry specifications

General

Imagemagick provides a number of commandline tools, none of which are named imagemagick, but rather:

  • convert: create/modify an image and save as a new file
  • mogrify: makes changes to an image "in-place" (replacing the original -- use with caution!)
  • montage: automated "poster" maker that creates a "thumbnail" image of a number of images (in a grid with variable spacing and options like showing the filename)
  • identify: display information about an image
  • display: show an image in a window (may not work on OS X, use the "open" command instead)

How to check if ImageMagick is installed

Type the name of one of the above commands in a terminal/shell, such as:

convert

Installing ImageMagick

In Linux, ImageMagick should either already be installed, or is available via whatever package manager the distribution supports. In Debian/Ubuntu:

sudo apt-get install imagemagick

or on mac ox, try:

brew install imagemagick

Resizing A folder of Images with mogrify

DANGER: this replaces all the images in the current folder with thumbnails, so you'd make a copy first!

mogrify -resize 320x240 *

Seeing what version of ImageMagick you have

Use the --version option with an ImageMagick command.

convert --version

Creating new images (without changing any originals)

Use convert. Convert always produces a new output file, generally you give the output file at the end of the command.

convert original.png -resize 160x120 icon.png


Modifying images "in-place" (changing the originals)

Use mogrify. Mogrify supports the same options as convert, only it modifies it's input, replacing the original (so you need to be careful with it).

Mogrify can be used with a wildcard to modify many files at once.

mogrify -resize 320x240 *.JPG


Getting Information about an Image

identify original.png

Displaying an image

display foo.png

pdfunite

From package: poppler-utils

Cutting

Cutting out a particular rectangle from an image

The format of the crop option is: WIDTHxHEIGHT+LEFT+TOP

For instance, to extract a 256 pixel square from an image 500 pixels from the left, at the top (0):

convert FILE0058.JPG -crop 256x256+500+0 tile.jpg


Cuting an image up into tiles or strips / "Cookie Cutting"

The crop command, when not given a specific position to cut out, will repeat as many times as it can, "cookie-cutter style", producing a series of images.

convert original.png -crop 64x64 tile%04d.png
convert original.png -crop 64x strip%04d.png
convert original.png -crop x64 bar%04d.png

Transforming

Converting/Changing image formats

convert original.png new.jpg
convert original.png -quality 1 lo.jpg


Resizing images

convert -resize 640x640 FILE0058.JPG work.png
convert -resize 640x640! FILE0058.JPG work.png


Assembling

Creating an animated gif from multiple images

convert tile*.png slide.gif
convert -delay 5 -dispose background -page +0+0 tile*.png slide.gif


Overlaying/Combining 2 images into a new image

Use composite. Composite is both a command-line tool on its own, and also it's available via the "-composite" option of convert. Note that the order of things is different depending on which way you use.

Creating a "contact sheet" / table of images

Use montage.

Arrange the frames as tiles on new jpg files. Geometry describes how big each image is resized to (640) and the spacing in between the tiles (+10+10).

%04d in the output filename means that the results are numbered starting from 0001 (0-padded to 4 places).

montage -geometry '640x640>+10+10' -tile 1x3 /*.jpg test%04d.jpg

Drawing

TODO: check circle parameters (radius one number only?!)

convert -size 300x300 xc:lightgray -fill black -draw 'rectangle 0,0 150,150' rect.gif
convert -size 300x300 xc:lightgray -fill black -draw 'circle 150,150 50,40' circle.gif


Finding more examples of drawing with ImageMagick

http://www.imagemagick.org/Usage/draw/#primitives