├── svg2png.py
├── README.md
└── cards-svg
├── 2S.svg
├── 3S.svg
├── 4S.svg
├── 5S.svg
├── 6S.svg
├── 2C.svg
├── 7S.svg
├── 8S.svg
├── 3C.svg
├── 9S.svg
├── 4C.svg
├── 5C.svg
├── Joker1.svg
├── 6C.svg
├── 2H.svg
├── 10S.svg
├── AC.svg
├── Joker2.svg
├── 3H.svg
├── 7C.svg
└── 2D.svg
/svg2png.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | """
4 | Copyright 2014 Peter Tripp
5 | Licensed under the MIT License: http://opensource.org/licenses/MIT
6 | """
7 |
8 | import argparse
9 | import os
10 | import subprocess
11 |
12 | if __name__=="__main__":
13 | parser = argparse.ArgumentParser(description="Generate fixed width PNGs from SVGs")
14 | parser.add_argument("-i", "--inputdir", required=True, help="Input directory of SVGs")
15 | parser.add_argument("-o", "--outputdir", required=True, help="Output directory of PNGs")
16 | parser.add_argument("-v", "--verbose", action="store_true", default=False, help="No output")
17 | parser.add_argument("-x", "--nocrush", action="store_true", default=False, help="Don't optimize resulting PNGs")
18 | parser.add_argument("-n", "--dry-run", action="store_true", default=False, help="Show commands without running them")
19 | parser.add_argument("-w", "--width", required=True, type=int, help="PNG output width")
20 |
21 | args = parser.parse_args()
22 | if not os.path.exists(args.inputdir):
23 | parser.error('Input directory does not exist')
24 | elif " " in args.inputdir or " " in args.outputdir :
25 | parser.error('Input directory or output directory contains a space.')
26 | #trailing slashes
27 | if args.inputdir[-1] != os.sep : args.inputdir += os.sep
28 | if args.outputdir[-1] != os.sep : args.outputdir += os.sep
29 | if not os.path.exists(args.outputdir): os.makedirs(args.outputdir)
30 |
31 | cmd, counter = [], 0
32 | for (counter, filename) in enumerate(os.listdir(args.inputdir)):
33 | if not filename.endswith(".svg"):
34 | pass #print filename + ":" not .svg
35 | else :
36 | li = []
37 | name, ext = os.path.splitext(filename)
38 | infile = os.path.join(args.inputdir, filename)
39 | outfile = os.path.join(args.outputdir, name + ".png")
40 | li.append(["svg2png", "-w", str(args.width), infile, outfile])
41 | if not (args.nocrush):
42 | li.append(["optipng", "-o3", outfile, "-q"])
43 | #results in 3-5% space savings
44 | #li.append(["advdef", "-3", outfile, "-q"])
45 | cmd.append(list(li))
46 | if args.verbose : print "Found", counter, "files. Beginning conversion."
47 |
48 | for eachfile in cmd :
49 | for c in eachfile :
50 | if (args.dry_run or args.verbose):
51 | print ' '.join(c)
52 | if not args.dry_run:
53 | subprocess.call(c)
54 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vector Playing Cards
2 |
3 | This is a simple collection of SVG images defining a deck of playing cards (based on [vector-playing-cards][4]) and a script (svg2png.py) which will convert a folder of svg files into arbitrarily sized png files.
4 |
5 | ## Usage:
6 | svg2png.py [-h] -i INPUTDIR -o OUTPUTDIR [-q] [-x] [-n] -w WIDTH
7 |
8 | Generate fixed width PNGs from SVGs
9 | optional arguments:
10 | -h, --help show this help message and exit
11 | -i INPUTDIR Input directory of SVGs
12 | -o OUTPUTDIR Output directory of PNGs
13 | -v, --verbose Verbose output
14 | -x, --nocrush Don't optimize resulting PNGs
15 | -n, --dry-run Show commands without running them
16 | -w WIDTH PNG output width
17 |
18 | ## Example use:
19 |
20 | * Simple: Convert SVGs to 300px wide uncompressed PNGs:
21 |
22 | `python svg2png.py -v -x -i cards-svg -o cards-png-300px -w 300`
23 |
24 | * Normal: Create SVGs to 320px wide optimized PNGs suppressing all status output
25 |
26 | `python svg2png.py -i cards-svg -o cards-png-320px -w 320`
27 |
28 |
29 | ## Prerequisites:
30 | To generate custom PNG images, you'll want the following tools:
31 |
32 | * MacOSX:
33 | * Homebrew: `ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"`
34 | * svg2png: `brew install svg2png`
35 | * optipng: `brew install optipng`
36 | * advdef: `brew install advancecomp`
37 | * montage: `brew install imagemagick`
38 |
39 | * Python 2.7 (generate-png.py uses argparse which is Python 2.7 only)
40 |
41 | ## Notes:
42 | Non optimized PNGs are approximately a third larger.
43 |
44 | ##License
45 |
46 | These images, scripts and subsequent transformational output (e.g. custom sized PNGs) are released into the public domain or optionally licensed under the [WTFPL][2] in juristictions where the public domain is not a recognized legal concept. Either way, do as you see fit: relicense, embed in commercial, non-commercial or open-source software, etc.
47 |
48 | The original source images were released by [Byron Knoll][3] into the public domain on Google Code as [vector-playing-cards][4] . Perhaps send him
49 |
50 |
51 | [1]: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
52 | [2]: http://en.wikipedia.org/wiki/WTFPL
53 | [3]: http://www.byronknoll.com/
54 | [4]: https://code.google.com/p/vector-playing-cards/
55 |
56 | [](https://bitdeli.com/free "Bitdeli Badge")
57 |
58 |
--------------------------------------------------------------------------------
/cards-svg/2S.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
148 |
--------------------------------------------------------------------------------
/cards-svg/3S.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
155 |
--------------------------------------------------------------------------------
/cards-svg/4S.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
164 |
--------------------------------------------------------------------------------
/cards-svg/5S.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
171 |
--------------------------------------------------------------------------------
/cards-svg/6S.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
178 |
--------------------------------------------------------------------------------
/cards-svg/2C.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
217 |
--------------------------------------------------------------------------------
/cards-svg/7S.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
187 |
--------------------------------------------------------------------------------
/cards-svg/8S.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
196 |
--------------------------------------------------------------------------------
/cards-svg/3C.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
225 |
--------------------------------------------------------------------------------
/cards-svg/9S.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
199 |
--------------------------------------------------------------------------------
/cards-svg/4C.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
231 |
--------------------------------------------------------------------------------
/cards-svg/5C.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
239 |
--------------------------------------------------------------------------------
/cards-svg/Joker1.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
279 |
--------------------------------------------------------------------------------
/cards-svg/6C.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
245 |
--------------------------------------------------------------------------------
/cards-svg/2H.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
309 |
--------------------------------------------------------------------------------
/cards-svg/10S.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
231 |
--------------------------------------------------------------------------------
/cards-svg/AC.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
259 |
--------------------------------------------------------------------------------
/cards-svg/Joker2.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
289 |
--------------------------------------------------------------------------------
/cards-svg/3H.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
319 |
--------------------------------------------------------------------------------
/cards-svg/7C.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
253 |
--------------------------------------------------------------------------------
/cards-svg/2D.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
319 |
--------------------------------------------------------------------------------