-
Notifications
You must be signed in to change notification settings - Fork 4
/
gd.py
66 lines (49 loc) · 2.1 KB
/
gd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
GD module is an interface to the GD library written by Thomas Bouttel. It
allows your code to quickly draw images complete with lines, arcs, text,
multiple colors, cut and paste from other images, and flood fills, and
write out the result as a .GIF, .PNG, .JPEG, or .WBMP file. This is
particularly useful in World Wide Web applications, where .JPEG is
universally supported and PNG is the up-and-coming format used for inline
images. It has been extended in some ways from the original GD library.
"""
import _gd
from _gd import *
del image
# proxy the _gd.image type as a class so we can override it.
class image:
def __init__(self, *args):
if isinstance(args[0], image):
args = list(args)
args[0] = args[0]._image
self.__dict__["_image"] = _gd.image(*args)
def __getattr__(self, name):
return getattr(self._image, name)
def __setattr__(self, name, value):
return setattr(self._image, name, value)
def lines(self, points, color):
"draw a line along the sequence of points in the list or tuple using color"
prev = tuple(points[0])
for p in points[1:]:
p = tuple(p)
self._image.line(prev, p, color)
prev = p
def copyTo(self, im, *args):
return self._image.copyTo(im._image, *args)
def copyResizedTo(self, im, *args):
return self._image.copyResizedTo(im._image, *args)
def copyResampledTo(self, im, *args):
return self._image.copyResampledTo(im._image, *args)
def copyMergeTo(self, im, *args):
return self._image.copyMergeTo(im._image, *args)
def copyMergeGrayTo(self, im, *args):
return self._image.copyMergeGrayTo(im._image, *args)
def copyPaletteTo(self, im, *args):
return self._image.copyPaletteTo(im._image, *args)
def compare(self, im, *args):
return self._image.compare(im._image, *args)
def setBrush(self, im, *args):
return self._image.setBrush(im._image, *args)
def setTile(self, im, *args):
return self._image.setTile(im._image, *args)
# end of file.