Skip to content

ImageMagick

What Where
Official Page https://imagemagick.org
Source https://github.com/imagemagick/imagemagick
Download https://imagemagick.org/script/download.php
Install sudo apt install imagemagick or choco install imagemagick
Examples https://imagemagick.org/script/examples.php or https://imagemagick.org/script/

Simple Convert

Convert some PNGs into a PDF:

convert prefix-*.png FINAL.pdf

Convert all images in a folder from heic to jpg

magick mogrify -format jpg *.heic

GIF

Use ImageMagick to optimize a GIF

convert -layers Optimize input.gif output.gif

Resize

Resize image to given dimensions

convert file.jpg -resize 1024 × 768 "folder\file.jpg"

Create a square thumbnail or favicon using ImageMagick

convert file.png -background transparent -gravity Center -extent 1:1# -scale 32 file-32px.png

Diff Images

Using ImageMagick with git (Source) to see differences in images:

Set alias "diff-img"

git config --global alias.diff-img difftool\ -x\ \''compare -alpha copy "$LOCAL" "$REMOTE" png:- | montage -mode concatenate "$LOCAL" png:- "$REMOTE" png:- | display -title "$BASE: Local | Diff | Remote" png:-'\'

or as a script for ~/bin/git-diff-img

#!/usr/bin/env sh
# $@ images
exec git difftool -x '
  compare -alpha copy "$LOCAL" "$REMOTE" png:- |
  montage -mode concatenate "$LOCAL" png:- "$REMOTE" png:- |
  display -title "$BASE: Local | Diff | Remote" png:-
' "$@"

Execute against png images only:

git diff-img **.png