Generate Playing Cards with ImageMagick
I’m working on a Freecell solitaire card game for Android (here the page). A card game requires cards; but where can I take card images? Looking for them in Internet is not fun enough, much better to write a script to generate them!
We can use ImageMagick and a bash script to draw a deck of 52 cards. The idea is to use a simplified design good for smartphones’ small screens. We need to draw:
- A rectangular white background with rounded corners;
- The card symbol (A, 2, …, J, Q, K);
- The suit symbols (twice).
I found a public domain version of the suit symbols on Wikipedia, put in the public domain by Flanker. I just split it in four files, and then I exploited them in an ImageMagick command.
The command to use is
convert. It not only converts an image, but also can create a new one. For example:
creates a transparent image with the specified size.
To draw a white rectangle we may add the
Then we may want to write the card name with
–draw can help also with the suit symbols
If we want to save a bit of space we can reduce the number of colors
Then we can save the file
A small bash script may help us to generate 52 cards in the out subdirectory:
The script is hosted on github: https://github.com/epman/cardsgen