Switch to unified view

a/Allura/allura/model/filesystem.py b/Allura/allura/model/filesystem.py
...
...
18
import os
18
import os
19
from cStringIO import StringIO
19
from cStringIO import StringIO
20
import logging
20
import logging
21
21
22
import pylons
22
import pylons
23
import Image
23
import PIL
24
from gridfs import GridFS
24
from gridfs import GridFS
25
from tg import config
25
from tg import config
26
from paste.deploy.converters import asint
26
from paste.deploy.converters import asint
27
27
28
from ming import schema
28
from ming import schema
...
...
134
        height = image.size[0]
134
        height = image.size[0]
135
        width = image.size[1]
135
        width = image.size[1]
136
        if square and height != width:
136
        if square and height != width:
137
            sz = max(width, height)
137
            sz = max(width, height)
138
            if 'transparency' in image.info:
138
            if 'transparency' in image.info:
139
                new_image = Image.new('RGBA', (sz,sz))
139
                new_image = PIL.Image.new('RGBA', (sz,sz))
140
            else:
140
            else:
141
                new_image = Image.new('RGB', (sz,sz), 'white')
141
                new_image = PIL.Image.new('RGB', (sz,sz), 'white')
142
            if height < width:
142
            if height < width:
143
                # image is wider than tall, so center horizontally
143
                # image is wider than tall, so center horizontally
144
                new_image.paste(image, ((width-height)/2, 0))
144
                new_image.paste(image, ((width-height)/2, 0))
145
            elif height > width:
145
            elif height > width:
146
                # image is taller than wide, so center vertically
146
                # image is taller than wide, so center vertically
147
                new_image.paste(image, (0, (height-width)/2))
147
                new_image.paste(image, (0, (height-width)/2))
148
            image = new_image
148
            image = new_image
149
149
150
        if thumbnail_size:
150
        if thumbnail_size:
151
            image.thumbnail(thumbnail_size, Image.ANTIALIAS)
151
            image.thumbnail(thumbnail_size, PIL.Image.ANTIALIAS)
152
152
153
        thumbnail_meta = thumbnail_meta or {}
153
        thumbnail_meta = thumbnail_meta or {}
154
        thumbnail = cls(
154
        thumbnail = cls(
155
            filename=filename, content_type=content_type, **thumbnail_meta)
155
            filename=filename, content_type=content_type, **thumbnail_meta)
156
        with thumbnail.wfile() as fp_w:
156
        with thumbnail.wfile() as fp_w:
...
...
173
            content_type = utils.guess_mime_type(filename)
173
            content_type = utils.guess_mime_type(filename)
174
        if not content_type.lower() in SUPPORTED_BY_PIL:
174
        if not content_type.lower() in SUPPORTED_BY_PIL:
175
            return None, None
175
            return None, None
176
176
177
        try:
177
        try:
178
            image = Image.open(fp)
178
            image = PIL.Image.open(fp)
179
        except IOError as e:
179
        except IOError as e:
180
            log.error('Error opening image %s %s', filename, e)
180
            log.error('Error opening image %s %s', filename, e, exc_info=True)
181
            return None, None
181
            return None, None
182
182
183
        format = image.format
183
        format = image.format
184
        if save_original:
184
        if save_original:
185
            original_meta = original_meta or {}
185
            original_meta = original_meta or {}