Post

Stickers from text

I love the idea of being able to easily add branded text stickers (branded in color and font) to social media images. However, creating them can be a pain. You can always type text, but making it into something pretty requires masking or using an editor, like Canva, that may then own your images - er, text images.

So, I created a simple bash script that will take an array of text and create masked transparent images as output.

Here, I’ve created a directory structure on my Desktop

  • Desktop
    • texts
    • source
      • overlays
      • masks
        • text
echo "Starting Texts"
mainDir="${HOME}/Desktop"
sourceDir="${mainDir}/source"
maskDir="${mainDir}/source/masks/text"
overlayDir="${mainDir}/source/overlays"
textDir="${mainDir}/texts"

function makeTextMask {
  convert -size 1000x1000  -fill black -background white -strokewidth 1 -stroke black \
        -font Chalkduster -gravity center caption:"${2}"  +repage \
        -gravity Center $maskDir/mask$1.png
}

function makePrettyText {
  echo 'I am making texts from' $1
  title=${1##*/}
  title=${title%.*}
  MASKS=$maskDir/*
  n=0
  for m in $MASKS
    do
      convert $m -size 2400x2400 \
              tile:$1  \
              -compose Screen -composite -alpha on -transparent white $textDir/$title$n.png
      let n++
    done
}


# ensure we have the right dirs
if [ ! -e "${textDir}" ]; then
  mkdir $textDir
fi

STRINGS=("HAPPY" "SUPER" "#IRL" "perfect" "chill\nout" "(^o^)")
x=0
for lbl in "${STRINGS[@]}"
  do
    makeTextMask $x "${lbl}"
    let x++
  done

BACKS=$sourceDir/backs/*
for i in $BACKS
  do
    makePrettyText $i
  done

This script, I save as ‘make_stickers.sh’ and I can call it from my terminal like so:

jess:~/ $ make_stickers.sh        

It is straightforward to change the string array to be an argument of the function and not have to edit the function constantly.

This post is licensed under CC BY 4.0 by the author.