mirror of https://github.com/scrapy/scrapy.git
Merge pull request #2675 from simongartz/png-p-to-jpg-conversion-fix
[MRG+1] Fixes conversion of transparent PNG with palette images to jpg #2452
This commit is contained in:
commit
25f609e2a3
|
|
@ -132,6 +132,11 @@ class ImagesPipeline(FilesPipeline):
|
|||
background = Image.new('RGBA', image.size, (255, 255, 255))
|
||||
background.paste(image, image)
|
||||
image = background.convert('RGB')
|
||||
elif image.mode == 'P':
|
||||
image = image.convert("RGBA")
|
||||
background = Image.new('RGBA', image.size, (255, 255, 255))
|
||||
background.paste(image, image)
|
||||
image = background.convert('RGB')
|
||||
elif image.mode != 'RGB':
|
||||
image = image.convert('RGB')
|
||||
|
||||
|
|
|
|||
|
|
@ -96,6 +96,14 @@ class ImagesPipelineTestCase(unittest.TestCase):
|
|||
self.assertEquals(converted.mode, 'RGB')
|
||||
self.assertEquals(converted.getcolors(), [(10000, (205, 230, 255))])
|
||||
|
||||
# transparency case with palette: P and PNG
|
||||
COLOUR = (0, 127, 255, 50)
|
||||
im = _create_image('PNG', 'RGBA', SIZE, COLOUR)
|
||||
im = im.convert('P')
|
||||
converted, _ = self.pipeline.convert_image(im)
|
||||
self.assertEquals(converted.mode, 'RGB')
|
||||
self.assertEquals(converted.getcolors(), [(10000, (205, 230, 255))])
|
||||
|
||||
|
||||
class DeprecatedImagesPipeline(ImagesPipeline):
|
||||
def file_key(self, url):
|
||||
|
|
|
|||
Loading…
Reference in New Issue