Resize images to specific target size while padding remaining space with transparency

convert -auto-orient -background "#00000000" original.jpg -resize 720x576 -gravity center -extent 720x576 resized.png

Resize all images of a file-type inside a folder

for PHOTO in *.jpg
do
    convert -auto-orient -background "#00000000" "$PHOTO" -resize 720x576 -gravity center -extent 720x576 "resized/$PHOTO.png"
done

Replace a color in image with different color

convert input.png -fuzz 90% -fill "#628FDB" -opaque "#000000" star_blue.png
  • fuzz: Percentage matching of the color
  • opaque: Color to replace
  • fill: Color to replace with

Reverse the RGB colors in an image

convert input.png -channel RGB -negate output.png

Resize image and then crop center to fit target size

convert original.jpg -resize 720x576^ -gravity center -crop 720x576+0+0 +repage resized.png

Scale (not resize) an image

magick original.webp -scale 128x128 scaled.webp

Get info from an image file

Find more details here.

magick identify -format "%m %w %h %x %%y" input.jpg
# This gives an output like below
# JPEG 4960 7015 600 600
  • %m: Format of the image file (JPEG, PNG, WEBP, etc.)
  • %w: Width of the image (in pixels)
  • %h: Height of the image (in pixels)
  • %x: Resolution/Density in the x direction
  • %y: Resolution/Density in the y direction

Automation is exciting 🤖