~osomon/pyexiv2/pyexiv2-0.3

15 by Olivier Tilloy
Added a very simple python script that demonstrates how to use pyqt to display the thumbnail data extracted from a picture using the method Image.getThumbnailData().
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
4
# ******************************************************************************
5
#
241.2.1 by Olivier Tilloy
Updated copyright headers for 2010.
6
# Copyright (C) 2007-2010 Olivier Tilloy <olivier@tilloy.net>
15 by Olivier Tilloy
Added a very simple python script that demonstrates how to use pyqt to display the thumbnail data extracted from a picture using the method Image.getThumbnailData().
7
#
17 by Olivier Tilloy
Updated the todo list.
8
# This file is part of the pyexiv2 distribution.
15 by Olivier Tilloy
Added a very simple python script that demonstrates how to use pyqt to display the thumbnail data extracted from a picture using the method Image.getThumbnailData().
9
#
10
# pyexiv2 is free software; you can redistribute it and/or
11
# modify it under the terms of the GNU General Public License
12
# as published by the Free Software Foundation; either version 2
13
# of the License, or (at your option) any later version.
14
#
15
# pyexiv2 is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
# GNU General Public License for more details.
19
#
20
# You should have received a copy of the GNU General Public License
21
# along with pyexiv2; if not, write to the Free Software
22
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
23
#
243.1.3 by Olivier Tilloy
Adapted the pyqt thumbnail example.
24
# Author: Olivier Tilloy <olivier@tilloy.net>
15 by Olivier Tilloy
Added a very simple python script that demonstrates how to use pyqt to display the thumbnail data extracted from a picture using the method Image.getThumbnailData().
25
#
26
# ******************************************************************************
27
28
import sys
99.1.1 by Olivier Tilloy
Ported the getThumbnailData method to the API of libexiv2 0.18.
29
from PyQt4 import QtGui
243.1.3 by Olivier Tilloy
Adapted the pyqt thumbnail example.
30
from pyexiv2 import ImageMetadata
31
15 by Olivier Tilloy
Added a very simple python script that demonstrates how to use pyqt to display the thumbnail data extracted from a picture using the method Image.getThumbnailData().
32
33
if __name__ == '__main__':
243.1.3 by Olivier Tilloy
Adapted the pyqt thumbnail example.
34
    """
35
    Example of how to combine PyQt4 and pyexiv2 to display thumbnail data.
36
37
    Minimalistic example of how to load and display with PyQt the thumbnail data
38
    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.
41
42
    It is of course assumed that you have PyQt4 installed.
43
    """
44
    if (len(sys.argv) != 2):
45
        print 'Usage: ' + sys.argv[0] + ' path/to/picture/file/containing/jpeg/thumbnail'
46
        sys.exit(1)
47
48
    app = QtGui.QApplication([])
49
50
    # Load the image, read the metadata and extract the thumbnail data
51
    metadata = ImageMetadata(sys.argv[1])
52
    metadata.read()
53
    previews = metadata.previews
54
    if not previews:
55
        print "This image doesn't contain any thumbnail."
56
        sys.exit(1)
57
58
    # Get the largest preview available
59
    preview = previews[-1]
60
61
    # Create a pixmap from the thumbnail data
62
    pixmap = QtGui.QPixmap()
63
    pixmap.loadFromData(preview.data, 'JPEG')
64
65
    # Create a QT label to display the pixmap
66
    label = QtGui.QLabel(None)
67
    label.setPixmap(pixmap)
68
69
    # Show the application's main window
70
    label.show()
71
    sys.exit(app.exec_())
72