Skip to content

Instantly share code, notes, and snippets.

@rabssm
Last active May 7, 2020 14:56
Show Gist options
  • Save rabssm/10649a4193df84458b57427b1c4be2ff to your computer and use it in GitHub Desktop.
Save rabssm/10649a4193df84458b57427b1c4be2ff to your computer and use it in GitHub Desktop.
Imagemagick Tips
# Separate an image into RGB channels. Filenames 1, 2, 3 for red, green and blue respectively
convert image.jpg -channel RGB -separate channels_%d.png
# Convert an image to grayscale
convert image.jpg -set colorspace Gray -separate -average image.png
# Threshold an image
convert -threshold 75 image.jpg image-thresh.jpg
# Combine images using max pixel values of each image
convert image1.jpg image2.jpg -evaluate-sequence max image.png
# Average a set of fits files
convert image*.fits -evaluate-sequence mean -define quantum:format=floating-point -depth 32 result.fits
# Subtract a dark image from an image - 2 methods
convert dark.png image.png -evaluate-sequence subtract result.png
convert dark.png image.png -compose minus -composite result.png
# Watermark an image in lower right corner
convert -fill grey -transparent white -font "Liberation-Sans" -pointsize 96 label:"Watermark" -shade 120x45 watermark.png
composite -watermark 50% -gravity SouthEast -geometry +20+20 watermark.png image.jpg image-watermarked.png
########################################
# Large copyright watermark stamp an image
# Create a large copyright symbol
convert -size 1200x800 -gravity West -fill black -transparent white -font Arial -pointsize 800 label:"©" -shade 240x40 copyright.png
# Create the copyright name to fit inside
convert -fill black -transparent white -font Arial -pointsize 96 label:"Owner's Name" -shade 240x40 name.png
# Compose the 2 images in one watermark stamp
composite -gravity Center -geometry -25-20 name.png copyright.png stamp.png
# Add the watermark stamp to the main image
composite -watermark 15% -gravity South -geometry +20+200 stamp.png image.jpg stamped.jpg
########################################
# Overlay one image on another
convert input.png trees.png -gravity south -composite result.png
# Apply a scale function to an image. This power function improves bright lunar images
convert -fx "pow(u,4)" image.jpg image_pow.jpg
# Copy EXIF tags from one image to another
exiftool -TagsFromFile image1.jpg image2.jpg
# Change the EXIF time on an image
image_time="2019:10:02 20:06:34.33-05:00" exiftool -m -xmp:dateTimeOriginal=$image_time -xmp:dateTimeDigitized=$image_time -exif:dateTimeOriginal=$image_time -exif:dateTimeDigitized=$image_time image.jpg
# Overlay the filename on the image
convert input.jpg -gravity Southwest -pointsize 12 -fill white -annotate 0 '%f' output.jpg
# Rotate an image by 1 degree
convert input.jpg -distort ScaleRotateTranslate 1 +repage output.jpg
# Crop a white border around an image
convert input.png -flatten -fuzz 25% -trim +repage cropped.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment