1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
def convert_catalog(from_file, to_file, size=220) :
23
return __convert(from_file, to_file, size)
25
def convert(from_file, to_file):
27
__convert(from_file, to_file, size=95)
29
def __convert(from_file, to_file, size=95):
30
from PIL import Image, ImageDraw, ImageFilter
31
im = Image.open(from_file)
32
if float(im.size[1]/im.size[0])>2:
33
im = im.resize((im.size[0]*size/im.size[1], size))
35
im = im.resize((size,im.size[1]*size/im.size[0]))
36
newimg = Image.new('RGB', (im.size[0]+8,im.size[1]+8), (255,255,255) )
38
draw = ImageDraw.Draw(newimg)
39
draw.rectangle((6, im.size[1]-5, im.size[0], im.size[1]+5), fill=(90,90,90))
40
draw.rectangle((im.size[0]-5, 6, im.size[0]+5, im.size[1]), fill=(90,90,90))
43
newimg = newimg.filter(ImageFilter.BLUR)
44
newimg = newimg.filter(ImageFilter.BLUR)
45
newimg = newimg.filter(ImageFilter.BLUR)
47
newimg.paste(im, (0,0))
48
draw = ImageDraw.Draw(newimg)
49
draw.rectangle((0, 0, im.size[0], im.size[1]), outline=(0,0,0))
51
to_fp = file(to_file, 'wb')
52
newimg.save(to_fp, "JPEG")
58
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: