Skip to content

Instantly share code, notes, and snippets.

@ExecThTs
Created July 7, 2025 22:23
Show Gist options
  • Select an option

  • Save ExecThTs/9a1315afa612e34f63bdbea5a1263e4a to your computer and use it in GitHub Desktop.

Select an option

Save ExecThTs/9a1315afa612e34f63bdbea5a1263e4a to your computer and use it in GitHub Desktop.
Add a watermark to an image specified as argument. Set size of overlay image in % relative to original image.
echo "processing $1"
watermarklocation=/home/exec/Pictures/watermark.svg
originalsize=$(identify -ping -format '%w %h' "$1")
targetpercentage=25
watermarkbox=$(awk "BEGIN {print int(( ${originalsize% *} + ${originalsize#* } ) / 2 * ( $targetpercentage * 0.01 ) + 0.5)}" )
magick composite \
-background none \
\( "$watermarklocation" -geometry "$watermarkbox" \) \
-compose over \
"$1" \
-gravity southwest \
-geometry 50% \
-quality 95 \
"$(dirname "$1")/$(basename "$1" .jpg).wm.jpg"
echo "done $(dirname "$1")/$(basename "$1" .jpg).wm.jpg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment