Skip to content

Instantly share code, notes, and snippets.

@brouberol
Created June 8, 2024 08:29
Show Gist options
  • Save brouberol/b5ce880fd02cdc1b8415bde938432a22 to your computer and use it in GitHub Desktop.
Save brouberol/b5ce880fd02cdc1b8415bde938432a22 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
img=$1
circle_img=$2
token_img="$(echo "$img" | cut -d. -f1)-token.$(echo "$img" | cut -d. -f2)"
# Crop the image to a circle
magick "$img" \( \
+clone \
-threshold 101% \
-fill white \
-draw 'circle %[fx:int(w/2)],%[fx:int(h/2)] %[fx:int(w)],%[fx:int(h/2)]' \
\) -channel-fx '| gray=>alpha' \
"$token_img"
# Get the image dimensions
img_dim=$(identify "$token_img" | awk '{ print $3 }')
# Overimpose the circle PNG over the circle image
magick "${token_img}" "${circle_img}" -gravity Center -geometry "${img_dim}" -composite "${token_img}"
echo ${token_img}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment