I need this one
[longneck.git] / longneck.py
blobcd0efa10df0116919a3c42ffce2fae8ff4fb916a
1 #!/usr/bin/python
3 import pygame
4 from optparse import OptionParser
5 import os.path
7 parser = OptionParser()
9 parser.add_option("-x", "--width",
10 dest="width",
11 type='int',
12 default=500,
13 help="internal width of the new image in pixels (minimal: 330)")
15 parser.add_option("-y", "--height",
16 dest="height",
17 type='int',
18 default=500,
19 help="internal height of the new image in pixels (minimal: 370)")
21 parser.add_option("-w", "--scalewidth",
22 dest="scalewidth",
23 type='int',
24 help="final width of the new image in pixels")
26 parser.add_option("-g", "--scaleheight",
27 dest="scaleheight",
28 type='int',
29 help="final height of the new image in pixels")
31 parser.add_option("-c", "--scale",
32 dest="scale",
33 type='float',
34 help="scale factor for the output")
36 parser.add_option("-f", "--file",
37 dest="file",
38 default="longneck.png",
39 help="write to this file, default: longneck.png")
41 parser.add_option("-p", "--params",
42 dest="params",
43 action="store_true",
44 help="out used parameters int the output filename")
46 (options, args) = parser.parse_args()
48 width, height = max(330, options.width), max(370, options.height)
50 suffix = "x%sy%s" % (width, height)
52 head = pygame.image.load(os.path.join('data', 'head.png'))
53 desk = pygame.image.load(os.path.join('data', 'desk.png'))
55 target = pygame.Surface((width, height))
56 target.fill(pygame.Color('white'))
57 target.blit(head, head.get_rect())
58 desk_rect = desk.get_rect()
59 desk_rect.right = width
60 desk_rect.bottom = height
61 target.blit(desk, desk_rect)
63 start = (112,124)
64 end = (width - 200, height - 111)
65 line_width = 5
67 pygame.draw.line(target, pygame.Color('black'), start, end, line_width)
69 if options.scale:
70 out_surface = pygame.transform.smoothscale(target, (width * options.scale, height * options.scale))
71 suffix += "s%f" % options.scale
72 elif options.scaleheight and options.scalewidth:
73 out_surface = pygame.transform.smoothscale(target, (options.scalewidth, options.scaleheight))
74 suffix += "w%sg%s" % (options.scalewidth, options.scaleheight)
75 else:
76 out_surface = target
78 parts = options.file.split('.')
79 if options.params:
80 options.file = '.'.join(parts[:-1] + [suffix, parts[-1]])
82 pygame.image.save(out_surface, options.file)