4 from optparse
import OptionParser
7 parser
= OptionParser()
9 parser
.add_option("-x", "--width",
13 help="internal width of the new image in pixels (minimal: 330)")
15 parser
.add_option("-y", "--height",
19 help="internal height of the new image in pixels (minimal: 370)")
21 parser
.add_option("-w", "--scalewidth",
24 help="final width of the new image in pixels")
26 parser
.add_option("-g", "--scaleheight",
29 help="final height of the new image in pixels")
31 parser
.add_option("-c", "--scale",
34 help="scale factor for the output")
36 parser
.add_option("-f", "--file",
38 default
="longneck.png",
39 help="write to this file, default: longneck.png")
41 parser
.add_option("-p", "--params",
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
)
64 end
= (width
- 200, height
- 111)
67 pygame
.draw
.line(target
, pygame
.Color('black'), start
, end
, line_width
)
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
)
78 parts
= options
.file.split('.')
80 options
.file = '.'.join(parts
[:-1] + [suffix
, parts
[-1]])
82 pygame
.image
.save(out_surface
, options
.file)