Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

do not degrade JPEG files.

Anubhav Patel25e616fa04bf
diff --git a/scrapy/pipelines/images.py b/scrapy/pipelines/images.py
index a1457c7e9..add606a2e 100644
--- a/scrapy/pipelines/images.py
+++ b/scrapy/pipelines/images.py
@@ -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