Making a Printable, Wallet-Sized Starbucks Gift Card
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.
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 \
mybar.png
-density 1200 mybar.eps
reads in the input image and rasterizes it at 1200 DPI- the argument to the
-resize
operator uses command substitution to calculate the number of pixels in 3.375 inches by 2.125 inches at 1200 DPI -gravity center
and-background white
set options for placing the image within the page…- …which is defined by the
-extent
operator here, to be the same size -gravity south
,-stroke none
, and-fill black
all set options for the annotation, drawing it in black text at the bottom of the image- the
-annotate
operator places text of theCode
value (manually entered from the gift card page) below the bar code -shave 8x8
removes 8 pixels from each side, in preparation for them being added back by-border 8x8
soon after, in order to keep the image the same size despite the new border-gravity northwest
and the-extent
operator place the image at the top left of an 8.5×11 page, shifted down and to the right by 32 pixels
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!