From 4e8d6c7cbb6674b72c99f5b0b80e4e37a6a6536a Mon Sep 17 00:00:00 2001 From: silencewwt Date: Tue, 21 Apr 2015 19:29:10 +0800 Subject: [PATCH] file format of Image Captcha can be specified --- captcha/image.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/captcha/image.py b/captcha/image.py index 61af3a8..83cef5b 100644 --- a/captcha/image.py +++ b/captcha/image.py @@ -31,25 +31,27 @@ else: class _Captcha(object): - def generate(self, chars): + def generate(self, chars, format='png'): """Generate an Image Captcha of the given characters. :param chars: text to be generated. + :param format: image file format """ im = self.generate_image(chars) out = BytesIO() - im.save(out, format='png') + im.save(out, format=format) out.seek(0) return out - def write(self, chars, output): + def write(self, chars, output, format='png'): """Generate and write an image CAPTCHA data to the output. :param chars: text to be generated. :param output: output destionation. + :param format: image file format """ im = self.generate_image(chars) - return im.save(output, format='png') + return im.save(output, format=format) class WheezyCaptcha(_Captcha):