mirror of https://github.com/scrapy/scrapy.git
do not degrade JPEG files.
This commit is contained in:
parent
d346b8cb0f
commit
25e616fa04
|
|
@ -127,7 +127,7 @@ class ImagesPipeline(FilesPipeline):
|
|||
raise ImageException("Image too small (%dx%d < %dx%d)" %
|
||||
(width, height, self.min_width, self.min_height))
|
||||
|
||||
image, buf = self.convert_image(orig_image)
|
||||
image, buf = self.convert_image(orig_image, BytesIO(response.body))
|
||||
yield path, image, buf
|
||||
|
||||
for thumb_id, size in six.iteritems(self.thumbs):
|
||||
|
|
@ -135,7 +135,7 @@ class ImagesPipeline(FilesPipeline):
|
|||
thumb_image, thumb_buf = self.convert_image(image, size)
|
||||
yield thumb_path, thumb_image, thumb_buf
|
||||
|
||||
def convert_image(self, image, size=None):
|
||||
def convert_image(self, image, response_body, size=None):
|
||||
if image.format == 'PNG' and image.mode == 'RGBA':
|
||||
background = Image.new('RGBA', image.size, (255, 255, 255))
|
||||
background.paste(image, image)
|
||||
|
|
@ -152,6 +152,9 @@ class ImagesPipeline(FilesPipeline):
|
|||
image = image.copy()
|
||||
image.thumbnail(size, Image.ANTIALIAS)
|
||||
|
||||
if not size and image.format == 'JPEG':
|
||||
return image, response_body
|
||||
|
||||
buf = BytesIO()
|
||||
image.save(buf, 'JPEG')
|
||||
return image, buf
|
||||
|
|
|
|||
Loading…
Reference in New Issue