-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathimage_generator.py
44 lines (40 loc) · 1.15 KB
/
image_generator.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
import Image, gtk
import base64
import sys
from array import array
class screenshot:
def __init__(self):
self.img_width = gtk.gdk.screen_width()
self.img_height = gtk.gdk.screen_height()
self.screengrab = gtk.gdk.Pixbuf(
gtk.gdk.COLORSPACE_RGB,
False,
8,
self.img_width,
self.img_height)
def take(self):
self.screengrab.get_from_drawable(
gtk.gdk.get_default_root_window(),
gtk.gdk.colormap_get_system(),
0, 0, 0, 0,
self.img_width,
self.img_height)
final_screengrab = Image.frombuffer(
"RGB",
(self.img_width, self.img_height),
self.screengrab.get_pixels(),
"raw",
"RGB",
self.screengrab.get_rowstride(),
1)
return final_screengrab
if __name__ == '__main__':
import time
screenshot = screenshot()
im = screenshot.take()
im.save("temp.jpg", "JPEG")
"""f = open("temp.jpg", "rb")
bytes = bytearray(f.read())
print sys.getsizeof(bytes)
stri = base64.b64encode(bytes)
print sys.getsizeof(stri)"""