Skip to content

Instantly share code, notes, and snippets.

@linnil1
Created August 17, 2023 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linnil1/cadffe6eaef54d741855a2242f6709fe to your computer and use it in GitHub Desktop.
Save linnil1/cadffe6eaef54d741855a2242f6709fe to your computer and use it in GitHub Desktop.
Adding Text Watermark to Images with Random Rotation using ImageMagick and Docker (Supports CJK)

Adding Text Watermark to Images with Random Rotation using ImageMagick and Docker (Supports CJK)

TL;DR

./watermark.sh input.jpg "僅供 linnil1 使用" output.jpg /OTF/TraditionalChinese/NotoSansCJKtc-Regular.otf

#!/bin/sh
podman run -it --rm \
    -v $4:/font/noto_sans_tc.otf:ro \
    -v $PWD:/app -w /app \
    docker.io/dpokidov/imagemagick \
    \( $1 -strip -interlace Plane -gaussian-blur 0.1 -resize 1500x1500 -quality 90% \) \
    \( -size 1500x1500 xc:none -pointsize 100 -fill "rgba(0,0,0,0.2)" -gravity center -font "/font/noto_sans_tc.otf" \
       -draw "rotate -$((RANDOM % 60)) text 0,0 '$2'" \) \
    -gravity center -composite $3

Requirements

  • Docker or Podman installed
  • Download a Chinese font, e.g., NotoSansCJK TC

Demo

Before: image

After: I changed the color to rgba(255,255,255,0.2) and removed -gaussian-blur 0.1 for better text quality: image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment