Imagemagick

Useful magick for images.

Imagemagick
Contents

Since we are going text/prg based for most things, we may consider imagemagick as a fairly regular replacement for gimp. This effort will also lead to understanding graphic software terminology.

Imagemagick website and Examples of ImageMagick Usage

Waiting items below will be elaborated on and some eliminated.

as explained here, the idea is to separate frames, join them, put it all back together: convert 1.gif -coalesce a-%04d.gif convert 2.gif -coalesce b-%04d.gif

for f in a-*.gif; do convert $f ${f/a/b} +append $f; done # append frames

convert -loop 0 -delay 20 a-*.gif result.gif # rejoin frames

in a dir with jpg,png this is the sort of thing that can be done: magick montage -geometry 99x55>+2+2 -tile 4x1 *.{jpg,png} 00.jpg

magick amazon-homepage.png -crop 2560x1440+1920+0 tmp.png

can use magick display to determine parameters though it is a bit awkward

convert test.png -transparent white trans.png

ImageMagick command-line consists of

  • one or more required input filenames:
    • filename globbing magick *.jpg images.gif
    • explicit image format magick -size 640x480 -depth 8 rgb:image image.png
    • using built-in images and patterns magick -size 640x480 pattern:checkerboard checkerboard.png
    • STDIN, STDOUT, and file descriptors not sure what is going on??
    • selecting certain frames from an image magick ‘images.gif[0]’ image.png magick ‘images.gif[0-3]’ images.mng
    • selecting a region of an image magick -size 6000x4000 -depth 8 ‘rgb:image[600x400+1900+2900]’ image.jpg
    • forcing an inline image resize magick ‘*.jpg’ -resize 120x120 thumbnail%03d.png but better magick ‘*.jpg[120x120]’ thumbnail%03d.png
    • forcing an inline image crop magick ‘*.jpg’ -crop 120x120+10+5 thumbnail%03d.png
    • filename references magick @myimages.txt mymovie.gif magick image-%d.jpg[1-5]
  • zero, one, or more image settings.
  • zero, one, or more image operators.
  • zero, one, or more image sequence operators.
  • zero, one, or more image stacks.
  • zero or one output image filenames

magick tmp.jpg -resample 10% -sharpen 0x2 -background none -flatten 00.jpg

Without the last 3 parameters the corners came out black instead of transparent.

magick input.png -channel RGB -negate output.png complements every color.

To just to the blacks and whites PP says use:

magick input.png \
  \( -clone 0 -colorspace HSL -channel Lightness -separate +channel -negate \) \
  \( -clone 0 -fill white -colorize 100 \) \
  -compose Luminize -composite \
  output.png

This command does the following:

  • Creates a copy of the input image and extracts its lightness channel.
  • Negates the lightness channel, which inverts black and white.
  • Creates another copy of the input image and turns it completely white.
  • Combines the negated lightness with the white image using the Luminize composition method.
  • This approach will invert black and white while preserving other colors14. It works by manipulating the lightness channel in the HSL colorspace, which affects only the brightness of the pixels without changing their hue or saturation6.

For even more control:

magick input.png \
  \( -clone 0 -colorspace HSL -channel Lightness -separate +channel -threshold 5%,95% -negate \) \
  \( -clone 0 -fill white -colorize 100 \) \
  -compose Luminize -composite \
  output.png

Related Content