imagemagick

Resize images with imagemagick

Install imagemagick from homebrew:

brew install homebrew

e.g. reduce size of all JPGs in a folder by 50% and store them as a file name as “samll_origFName.jpg”

for file in *.jpg; do convert $file -resize 50% small_$file ; done

Bulk crop images

Often you might need to crop images to a fixed size. Cropping few images using Preview is fine however, it can be automated with ImageMagick wit this syntax:

for filename in *.png; do\
  convert $filename -crop 1920x1080+100+25 "cropped/$filename"
  echo "$filename done"
done

Here with 1920x1080+100+25 syntax a 1920 px (w) x 1080px (h) image will be cropped 100 px away from the left edge and 25 px away from the top edge of the image. We can also write it a parameterized version which is easier to edit.

mkdir cropped
width=1920
height=1080
left=100
top=20

# This is for PNGs, change the extension if you need to crop JPEGs
for filename in *.png; do\
  convert $filename -crop "${width}x${width}+${left}+${top}" "cropped/$filename"
  echo "$filename done"
done
Previous
Next