-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.py
30 lines (24 loc) · 834 Bytes
/
image.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
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GdkPixbuf, GLib
from gi.repository import Gio
class Image():
def __init__(self, fileName):
super().__init__()
if fileName is not None:
self.pixbuf = GdkPixbuf.Pixbuf().new_from_file(fileName)
else:
self.pixbuf = None
def GetPixbuf(self):
return(self.pixbuf)
def SetFromStream(self, stream):
if self.pixbuf is None:
self.pixbuf = GdkPixbuf.Pixbuf()
input_stream = Gio.MemoryInputStream.new_from_data(stream, None)
self.pixbuf = self.pixbuf.new_from_stream(input_stream, None)
return self
def Scale(self, w, h):
if self.pixbuf is not None:
return self.pixbuf.scale_simple(w, h, GdkPixbuf.InterpType.BILINEAR)
else:
return self.pixbuf