Don't convert images blindly to RGB. Only convert to RGB or RGBA when saving to JPEG and mode is 'P'. documents.tests.test_models.MultiPageTiffTestCase passes again.
This commit is contained in:
@@ -93,7 +93,7 @@ class Python(ConverterBase):
|
||||
file_object.seek(0)
|
||||
else:
|
||||
try:
|
||||
image = Image.open(self.file_object).convert('RGB')
|
||||
image = Image.open(self.file_object)
|
||||
except IOError as exception:
|
||||
error_message = _('Exception determining PDF page count; %s') % exception
|
||||
logger.error(error_message)
|
||||
|
||||
@@ -163,7 +163,7 @@ class ConverterBase(object):
|
||||
self.file_object.seek(0)
|
||||
|
||||
try:
|
||||
self.image = Image.open(self.file_object).convert('RGB')
|
||||
self.image = Image.open(self.file_object)
|
||||
except IOError:
|
||||
# Cannot identify image file
|
||||
self.image = self.convert(page_number=page_number)
|
||||
@@ -176,7 +176,16 @@ class ConverterBase(object):
|
||||
self.seek(0)
|
||||
|
||||
image_buffer = StringIO()
|
||||
self.image.save(image_buffer, format=output_format)
|
||||
|
||||
new_mode = self.image.mode
|
||||
|
||||
if output_format.upper() == 'JPEG':
|
||||
if self.image.mode == 'P':
|
||||
new_mode = 'RGB'
|
||||
if 'transparency' in self.image.info:
|
||||
new_mode = 'RGBA'
|
||||
|
||||
self.image.convert(new_mode).save(image_buffer, format=output_format)
|
||||
image_buffer.seek(0)
|
||||
|
||||
return image_buffer
|
||||
|
||||
Reference in New Issue
Block a user