~ubuntu-branches/debian/stretch/phatch/stretch

« back to all changes in this revision

Viewing changes to phatch/lib/openImage.py

  • Committer: Bazaar Package Importer
  • Author(s): Stani M
  • Date: 2009-10-01 05:36:09 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20091001053609-wvy9yu0u3i6fuv4t
Tags: 0.2.2-1
* Upstream bugfix release (Closes LP: #236548, #436595, #437161, 
 #437376, #437852, #439108, #439359, #440273, #440956)
* debian/control: Dropped dependency python-wxgtk2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
import imtools
25
25
import system
 
26
import thumbnail
26
27
 
27
28
try:
28
29
    import pyexiv2
48
49
            return image
49
50
    # pil
50
51
    try:
51
 
        return open_image_with_pil(uri)
 
52
        image = open_image_with_pil(uri)
 
53
        ok = True
52
54
    except IOError, message:
53
 
        pass
54
 
    # tiff (which pil can only handle partly)
 
55
        ok = False
 
56
    # interlaced png
 
57
    if ok and not(image.format == 'PNG' and 'interlace' in image.info):
 
58
        return image
 
59
    # png, tiff (which pil can only handle partly)
55
60
    if local:
56
61
        image = open_image_without_pil(uri, ENHANCE_PIL)
 
62
        if image:
 
63
            image.info['Format'] = image.format
 
64
            image.format = format
 
65
            return image
57
66
    else:
58
67
        image = None
59
68
    if image is None:
78
87
    return open_image_exif(uri)
79
88
 
80
89
 
81
 
def thumb_from_file(filename, thumb_size=imtools.THUMB_SIZE,
82
 
        filter=Image.ANTIALIAS, write_cache=True, image=None,
83
 
        open_method=open_image_exif_thumb):
84
 
    return imtools.thumb_from_file(filename=filename, thumb_size=thumb_size,
85
 
        filter=filter, write_cache=write_cache, image=image,
86
 
        open_method=open_method)
 
90
def open_thumb(filename, image=None, open_image=open_image_exif_thumb,
 
91
        size=thumbnail.SIZE, save_cache=True):
 
92
    return thumbnail.open(filename=filename, image=image,
 
93
        open_image=open_image, size=size,
 
94
        save_cache=save_cache)
87
95
 
88
96
 
89
97
def open_image_with_pil(uri):
305
313
 
306
314
    def open_imagemagick(filename):
307
315
        """Open an image with Imagemagick."""
308
 
        command = '%s "%s" -flatten "%%s"'%(IMAGEMAGICK_CONVERT, filename)
 
316
        command = '%s "%s" -flatten -interlace none "%%s"'\
 
317
            %(IMAGEMAGICK_CONVERT, filename)
309
318
        return open_image_with_command(filename, command, 'imagemagick')
310
319
 
311
320
else:
403
412
 
404
413
ENHANCE_PIL = system.MethodRegister()
405
414
ENHANCE_PIL.register(['tiff'], open_libtiff)
 
415
ENHANCE_PIL.register(['png'], open_imagemagick)
406
416
 
407
417
VERIFY_WITHOUT_PIL = system.MethodRegister()
408
418
VERIFY_WITHOUT_PIL.register(['xcf'], verify_xcf)