Making a Printable, Wallet-Sized Starbucks Gift Cardchain link icon indicating a link to a heading

I recently received a Starbucks gift card via e-mail. I don’t have a Starbucks account, nor do I use their mobile app. However, the online gift card page shows a bar code, which I decided to print at wallet size so I don’t have to keep the email in my inbox until I use up the stored value.

the output barcode image

I started by saving the image from the page as displayed in my browser, which downloaded as CODE128.gif, giving me a hint to the format of the bar code. Next, I decoded the bar code using zbarimg (installable as zbar from Homebrew) and created a new, high-quality encapsulated PostScript(EPS) version of the bar code with the GNU barcode command (installable as gnu-barcode from Homebrew):

zbarimg -q --raw CODE128.gif | \
barcode -o mybar.eps -u in -g 3x1+0.25+0.5 -E -e code128

The option -u in tells barcode to use inches for the geometry option, and -g 3x1+0.25+0.5 creates a 3-inch × 1-inch bar code with 0.25 inches of horizontal margin and 0.5 inches of vertical margin. The -E option causes EPS output and the -e code128 option makes a CODE128 bar code. These dimensions create an image that will fit nicely in the size of a credit card.

Next, I created the image to be printed from mybar.eps using ImageMagick (installable as imagemagick from Homebrew):

magick \
  -density 1200 mybar.eps \
  -resize $(dc -e '3.375 1200 *p')x$(dc -e '2.125 1200 *p') \
  -gravity center -background white \
  -extent $(dc -e '3.375 1200 *p')x$(dc -e '2.125 1200 *p') \
  -gravity south -stroke none -fill black \
  -annotate +0+256 'Code: xxxxxxxx' \
  -shave 8x8 -bordercolor black -border 8x8 \
  -gravity northwest \
  -extent $(dc -e '8.5 1200 *p')x$(dc -e '11 1200 *p')-32-32 \

The seemingly-redundant operations -resize and the first -extent are necessary because ImageMagick by default preserves aspect ratio on resize, so after the -resize operation, the image will actually match the 3-inch × 1-inch aspect ratio at which it was created.

This command takes a fair amount of time to run, since it’s making a fairly large output image.

The output mybar.png can be printed to fill a page and then cut out around the border to fit in your wallet!