1#!/usr/bin/env python
2""" pygame.examples.headless_no_windows_needed
3
4How to use pygame with no windowing system, like on headless servers.
5
6Thumbnail generation with scaling is an example of what you can do with pygame.
7NOTE: the pygame scale function uses mmx/sse if available, and can be run
8  in multiple threads.
9"""
10useage = """-scale inputimage outputimage new_width new_height
11eg.  -scale in.png out.png 50 50
12
13"""
14
15import os
16import sys
17
18# set SDL to use the dummy NULL video driver,
19#   so it doesn't need a windowing system.
20os.environ["SDL_VIDEODRIVER"] = "dummy"
21
22import pygame as pg
23
24# Some platforms need to init the display for some parts of pg.
25pg.display.init()
26screen = pg.display.set_mode((1, 1))
27
28
29def scaleit(fin, fout, w, h):
30    i = pg.image.load(fin)
31
32    if hasattr(pg.transform, "smoothscale"):
33        scaled_image = pg.transform.smoothscale(i, (w, h))
34    else:
35        scaled_image = pg.transform.scale(i, (w, h))
36    pg.image.save(scaled_image, fout)
37
38
39def main(fin, fout, w, h):
40    """smoothscale image file named fin as fout with new size (w,h)"""
41    scaleit(fin, fout, w, h)
42
43
44if __name__ == "__main__":
45    if "-scale" in sys.argv:
46        fin, fout, w, h = sys.argv[2:]
47        w, h = map(int, [w, h])
48        main(fin, fout, w, h)
49    else:
50        print(useage)
51