Switch to unified view

a/Allura/allura/model/filesystem.py b/Allura/allura/model/filesystem.py
...
...
95
                'Content-Disposition',
95
                'Content-Disposition',
96
                'attachment;filename=%s' % self.filename)
96
                'attachment;filename=%s' % self.filename)
97
        return iter(fp)
97
        return iter(fp)
98
98
99
    @classmethod
99
    @classmethod
100
    def save_thumbnail(cls, filename, image,
101
                   content_type,
102
                   thumbnail_size=None,
103
                   thumbnail_meta=None,
104
                   square=False):
105
        format = image.format
106
        height = image.size[0]
107
        width = image.size[1]
108
        if square and height != width:
109
            sz = max(width, height)
110
            if 'transparency' in image.info:
111
                new_image = Image.new('RGBA', (sz,sz))
112
            else:
113
                new_image = Image.new('RGB', (sz,sz), 'white')
114
            if height < width:
115
                # image is wider than tall, so center horizontally
116
                new_image.paste(image, ((width-height)/2, 0))
117
            elif height > width:
118
                # image is taller than wide, so center vertically
119
                new_image.paste(image, (0, (height-width)/2))
120
            image = new_image
121
122
        if thumbnail_size:
123
            image.thumbnail(thumbnail_size, Image.ANTIALIAS)
124
125
        thumbnail_meta = thumbnail_meta or {}
126
        thumbnail = cls(
127
            filename=filename, content_type=content_type, **thumbnail_meta)
128
        with thumbnail.wfile() as fp_w:
129
            if 'transparency' in image.info:
130
                image.save(fp_w, format, transparency=image.info['transparency'])
131
            else:
132
                image.save(fp_w, format)
133
134
        return thumbnail
135
136
    @classmethod
100
    def save_image(cls, filename, fp,
137
    def save_image(cls, filename, fp,
101
                   content_type=None,
138
                   content_type=None,
102
                   thumbnail_size=None,
139
                   thumbnail_size=None,
103
                   thumbnail_meta=None,
140
                   thumbnail_meta=None,
104
                   square=False,
141
                   square=False,
...
...
121
                else:
158
                else:
122
                    image.save(fp_w, format)
159
                    image.save(fp_w, format)
123
        else:
160
        else:
124
            original = None
161
            original = None
125
162
126
        if square:
163
        thumbnail = cls.save_thumbnail(filename, image, content_type, thumbnail_size, thumbnail_meta, square)
127
            height = image.size[0]
164
128
            width = image.size[1]
129
            sz = max(width, height)
130
            if 'transparency' in image.info:
131
                new_image = Image.new('RGBA', (sz,sz))
132
            else:
133
                new_image = Image.new('RGB', (sz,sz), 'white')
134
            if height < width:
135
                # image is wider than tall, so center horizontally
136
                new_image.paste(image, ((width-height)/2, 0))
137
            elif height > width:
138
                # image is taller than wide, so center vertically
139
                new_image.paste(image, (0, (height-width)/2))
140
            if height != width:
141
                image = new_image
142
        if thumbnail_size:
143
            image.thumbnail(thumbnail_size, Image.ANTIALIAS)
144
        thumbnail_meta = thumbnail_meta or {}
145
        thumbnail = cls(
146
            filename=filename, content_type=content_type, **thumbnail_meta)
147
        with thumbnail.wfile() as fp_w:
148
            if 'transparency' in image.info:
149
                image.save(fp_w, format, transparency=image.info['transparency'])
150
            else:
151
                image.save(fp_w, format)
152
        return original, thumbnail
165
        return original, thumbnail
153
        
166
        
154
    def is_image(self):
167
    def is_image(self):
155
        return (self.content_type
168
        return (self.content_type
156
                and self.content_type.lower() in SUPPORTED_BY_PIL)
169
                and self.content_type.lower() in SUPPORTED_BY_PIL)