21
21
# along with pyexiv2; if not, write to the Free Software
22
22
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
25
# File: pyqt-example.py
26
# Author(s): Olivier Tilloy <olivier@tilloy.net>
24
# Author: Olivier Tilloy <olivier@tilloy.net>
28
26
# ******************************************************************************
30
from pyexiv2 import ImageMetadata
34
33
if __name__ == '__main__':
36
Example of how to combine pygtk and pyexiv2 to display thumbnail data.
38
Minimalistic example of how to load and display with pygtk the thumbnail
39
data extracted from an image using the method Image.getThumbnailData().
40
The path to the image file from which the thumbnail data should be extracted
41
should be passed as the only argument of the script.
43
It is of course assumed that you have pygtk installed.
45
if (len(sys.argv) != 2):
46
print 'Usage: ' + sys.argv[0] + ' path/to/picture/file/containing/jpeg/thumbnail'
49
app = gtk.Window(gtk.WINDOW_TOPLEVEL)
51
# Load the image, read the metadata and extract the thumbnail data
52
image = pyexiv2.Image(sys.argv[1])
54
ttype, tdata = image.getThumbnailData()
56
# Create a GTK pixbuf loader to read the thumbnail data
57
pbloader = gtk.gdk.PixbufLoader()
59
# Get the resulting pixbuf and build an image to be displayed
60
pixbuf = pbloader.get_pixbuf()
62
imgwidget = gtk.Image()
63
imgwidget.set_from_pixbuf(pixbuf)
65
# Show the application's main window
66
# Note: closing the window will not terminate the application as no
67
# appropriate signal has been defined.
35
Example of how to combine pygtk and pyexiv2 to display thumbnail data.
37
Minimalistic example of how to load and display with pygtk the thumbnail
38
data extracted from an image.
39
The path to the image file from which the thumbnail data should be extracted
40
should be passed as the only argument of the script.
42
It is of course assumed that you have pygtk installed.
44
if (len(sys.argv) != 2):
45
print 'Usage: ' + sys.argv[0] + ' path/to/picture/file/containing/jpeg/thumbnail'
48
app = gtk.Window(gtk.WINDOW_TOPLEVEL)
49
app.connect('destroy', lambda app: gtk.main_quit())
51
# Load the image, read the metadata and extract the thumbnail data
52
metadata = ImageMetadata(sys.argv[1])
54
previews = metadata.previews
56
print "This image doesn't contain any thumbnail."
59
# Get the largest preview available
60
preview = previews[-1]
62
# Create a pixbuf loader to read the thumbnail data
63
pbloader = gtk.gdk.PixbufLoader()
64
pbloader.write(preview.data)
65
# Get the resulting pixbuf and build an image to be displayed
66
pixbuf = pbloader.get_pixbuf()
68
imgwidget = gtk.Image()
69
imgwidget.set_from_pixbuf(pixbuf)
71
# Show the application's main window