image resize and watermark batch

$ mogrify -resize 640 *.jpg

If you want the height, just add a x :

$ mogrify -resize x640 *.jpg

You can also specify maximum width and height, that can be useful if you have big images and you don’t want a width larger than x and a height larger than y but you don’t want to resize little images in the same folder. Here is an example resizing images if the width is larger than 1280 or height larger than 1024 :

$ mogrify -resize '1280x1024>' *.jpg

To watermark use:
$ composite -dissolve 50% -gravity center -quality 100 Watermark.png Tux.jpg Tuxwm.jpg

sample script:

#!/bin/sh

# change directory to the desired one
cd $1

# create resized dir
# warning! if exists, the pictures will be overwritten!
mkdir resized

# look up files with extensions
for fname in *.*; do

  # this is the resize and slightly sharpen part
  echo "resizing $fname"
  mogrify -sharpen 1 -quality 96% -write "./resized/$fname" -resize 800 "$fname"

  # this is the watermarking part (gravity center or SouthEast)
  echo "watermarking $fname"
  composite -compose atop -dissolve 60% -gravity SouthEast -quality 100 "/usr/local/bin/mettilogo.png" "./resized/$fname" "./resized/$fname"

done

 

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *