Skip to content

Instantly share code, notes, and snippets.

@TomFromThePool
Last active August 29, 2023 18:15
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 TomFromThePool/00936e7d701346b241ec27fbfb5fe3e5 to your computer and use it in GitHub Desktop.
Save TomFromThePool/00936e7d701346b241ec27fbfb5fe3e5 to your computer and use it in GitHub Desktop.
ImageMagick Quote of The Day Generator (ZSH)
#! /bin/zsh
#First, let's grab a random quote
RANDOM_QUOTE="https://api.quotable.io/quotes/random"
export QUOTE=$(curl -s $RANDOM_QUOTE | jq -r '.[0].content + "\n- " + .[0].author')
#Now, let's get some random colours
COLOUR_GEN=$(curl 'http://colormind.io/api/' --data-binary '{"model":"default"}' | jq '.result | map("rgb(" + join(",") + ")")')
export GRAD_A=$(jq -r '.[0]' <<< $COLOUR_GEN)
export GRAD_B=$(jq -r '.[4]' <<< $COLOUR_GEN)
#ImageMagick scripts don't easily support env-vars, so let's use envsubst instead
MGK_CMD=$(cat qotd.mgk | envsubst)
#Now let's get a temporary file handle for magick-script
magick-script =(echo $MGK_CMD)
-size 800x600
(
(
( gradient:${GRAD_A}-${GRAD_B} ) #Setup the gradient
( xc:none -draw 'roundrectangle 20,20,760,540,25,25' ) #Setup the rounded rect
-compose copy-opacity -composite #Merge, keeping opacity
)
( +clone -background black -shadow 20x5+5+5 ) +swap #Create a shadow version of the rect, and then swap it to the back
-compose over -composite #Merge layers together
)
(
( -background none -font Trebuchet-MS -fill '#eff' -stroke '#aaa' -strokewidth 2 -gravity center caption:"${QUOTE}" ) #Create text
( +clone -background black -shadow 40x2+2+2 ) +swap #Create a shadow version of the text, and then swap it to the back
-compose over -composite -geometry 740x500+10-30 #Merge with resize and offset
)
-composite -trim -write qotd.png #Merge everything together and write to disk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment