Задать вопрос

Тел: +7 965 3737 888

439

Просмотров

5

Ответов

thumbnail an image

Thumbnail an image.

Вопрос полезен? Да0/Нет0
file_3037.py(937.0б)
None

Ответы (5):

Ответdolilmao:13.04.2014
Ответ полезен? Да0/Нет0

I have been looking for somethink similar to this glad I found it

Ответlimodou:02.08.2007
Ответ полезен? Да0/Нет0

thanks to marioparris, I'v changed it.

Ответmarioparris:07.06.2007
Ответ полезен? Да0/Нет0

Also, change line 13 from: output_filename = get_default_thumbnail_filename(output_filename)

to: output_filename = get_default_thumbnail_filename(filename)

so it uses the filename of the file you are thumbnailing. If output_filename is None by default, then that causes a problem ;)

Ответlimodou:27.02.2007
Ответ полезен? Да0/Нет0

thanks

Ответfredrik:27.02.2007
Ответ полезен? Да0/Нет0

To avoid extra copies, I'd recommend changing

image = Image.open(filename)
image = image.convert('RGB')
image = image.resize(size, Image.ANTIALIAS)

to

image = Image.open(filename)
if image.mode not in ("L", "RGB"):
    image = image.convert('RGB')
image = image.resize(size, Image.ANTIALIAS)

The

image.save(file(output_filename, 'wb') ...

thing is also unnecessary; save() takes either a filename or a file object, so there's no need to open it yourself.

Cheers /F