Skip to content

Instantly share code, notes, and snippets.

@nisdis
Last active May 16, 2017 11:36
Show Gist options
  • Save nisdis/e6cdd6962099f2df3ea1121b99452b24 to your computer and use it in GitHub Desktop.
Save nisdis/e6cdd6962099f2df3ea1121b99452b24 to your computer and use it in GitHub Desktop.
This script can be used to resize and watermark tons of images with this single scripts esp. DSLR images to web friendly images
#!/bin/bash
###
# This script can be used to resize and watermark tons of images with this single script
#
#
# Requirements: Imagemagick package installed
# Debian: $ sudo atp-get install imagemagick
# MacOs: $ brew install imagemagick
#
#
# Usage: $ chmod 755 image_ready.sh
# $ ./image_ready.sh
#
# EDIT: water_txt -> "YOUR WATERMARK"
# ptsize -> <FONT-SIZE>
#
#
#
#
#
###
dirt=`pwd`
mdirt='share'
water_txt='nissim.io'
convrt=`which convert`
compst=`which composite`
mgrfy=`which mogrify`
let ptsize=50
let wpts=$ptsize*6
let hpts=$ptsize
cd "$dist"
if [ ! -d "$dirt/$mdirt" ]; then mkdir "$dirt/$mdirt" ; fi
$convrt -size $wpts'x'$hpts xc:grey30 -pointsize $ptsize -gravity center \
-draw "fill grey80 text 0,0 '$water_txt'" \
"$dirt/$mdirt/stamp_fgnd.png"
$convrt -size $wpts'x'$hpts xc:black -pointsize $ptsize -gravity center \
-draw "fill white text 1,1 '$water_txt' \
text 0,0 '$water_txt' \
fill black text -1,-1 '$water_txt'" \
+matte "$dirt/$mdirt/stamp_mask.png"
$compst -compose CopyOpacity "$dirt/$mdirt/stamp_mask.png" "$dirt/$mdirt/stamp_fgnd.png" "$dirt/$mdirt/stamp.png"
$mgrfy -trim +repage "$dirt/$mdirt/stamp.png"
for x in "$dirt"/*.jpg #$dirt/*.JPG $dirt/*.JPEG $dirt/*.jpg $dirt/*.jpeg
do
filename=$(basename "$x")
echo "converting: $filename"
$convrt "$x" -resize 1200x1200 \
-quality 80 \
"$dirt/$mdirt/$filename"
$compst -gravity SouthEast -geometry +10+10 "$dirt/$mdirt/stamp.png" "$dirt/$mdirt/$filename" \
"$dirt/$mdirt/$filename\.comp"
mv "$dirt/$mdirt/$filename\.comp" "$dirt/$mdirt/$filename"
done
rm -R "$dirt/$mdirt/stamp.png" "$dirt/$mdirt/stamp_mask.png" "$dirt/$mdirt/stamp_fgnd.png"
echo "Script: Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment