~osomon/phatch/extract-all-metadata

« back to all changes in this revision

Viewing changes to phatch/core/pil.py

  • Committer: Juho Vepsäläinen
  • Date: 2009-09-15 12:39:56 UTC
  • mfrom: (1294 trunk)
  • mto: This revision was merged to the branch mainline in revision 1306.
  • Revision ID: bebraw@gmail.com-20090915123956-k2ykiqq701aykzo3
Merged with trunk successfully.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
NEEDS_PYEXIV2 = _('pyexiv2 needs to be installed')+' (%s)'%WWW_PYEXIV2
71
71
 
72
72
DYNAMIC_VARS = set(('width', 'height', 'size', 'mode'))
73
 
EXT_BY_FORMATS = {
74
 
    'GIF': ['gif'],
75
 
    'JPEG': ['jpg', 'jpeg', 'jpe'],
76
 
    'PNG': ['png'],
77
 
    'TIFF': ['tif', 'tiff'],
78
 
}
79
 
FORMATS_BY_EXT = {}
80
 
for format, exts in EXT_BY_FORMATS.items():
81
 
    for ext in exts:
82
 
        FORMATS_BY_EXT[ext] = format
83
73
IMAGE_DEFAULT_DPI = 72
84
74
SEPARATOR = '_' #should be same as in core.translations
85
75
MONTHS = (_t('January'), _t('February'), _t('March'), _t('April'),
103
93
IMAGE_EXTENSIONS = [ext for ext in IMAGE_READ_EXTENSIONS
104
94
    if ext in formField.IMAGE_WRITE_EXTENSIONS]
105
95
 
106
 
BASE_VARS = ['dpi', 'compression', 'filename', 'format', 'orientation',
107
 
        'path', 'transparency', 'type']
 
96
BASE_VARS = ['dpi', 'compression', 'filename', 'format',
 
97
    'orientation', 'path', 'transparency', 'type']
108
98
 
109
99
 
110
100
def check_libtiff(compression):
162
152
    return imtools.open_image(uri)
163
153
 
164
154
 
165
 
def get_format(ext):
166
 
    return FORMATS_BY_EXT.get(ext.lower(), ext.upper())
167
 
 
168
 
 
169
155
def transpose(image, methods):
170
156
    """Transpose with a sequence of transformations, mainly useful
171
157
    for exif."""
685
671
        return tempfile.NamedTemporaryFile().name\
686
672
            +self.info['filename']+ext
687
673
 
688
 
    def call(self, command, check_exe=True, shell=None):
 
674
    def call(self, command, check_exe=True, shell=None, size=None):
689
675
        if shell is None:
690
676
            shell = not system.WINDOWS
691
677
        #get command line
692
678
        info = self.info
693
679
        layer = self.get_layer()
694
680
        image = layer.image
 
681
        if size != None and size[0] < image.size[0]:
 
682
            image = image.copy()
 
683
            image.thumbnail(size, Image.ANTIALIAS)
695
684
        #loop over input -> save to temp files
696
685
        temp_files = []
697
686
        done = []
701
690
            if not(source in done):
702
691
                ext = match.group(1)
703
692
                target = self.temp_filename(ext)
704
 
                try:
705
 
                    image.save(target)
706
 
                except Exception, error:
707
 
                    pass
 
693
                #try:
 
694
                imtools.save_safely(image,target)
 
695
                #except Exception, error:
 
696
                #    pass
708
697
                temp_files.append((source, target))
709
698
                done.append(source)
710
699
        #check if we have a file_in