Performance improvement: prevent unnecessary image.resize in TransformationZoom
Hi, in DocumentPage.get_image zoom_level is always set to an value, so TransformationZoom is always executed:
if zoom_level:
converter.transform(
transformation=TransformationZoom(percent=zoom_level)
)
So the self.image.resize is always done (also with zoom percent ==100) . I did a quick check if the PIL image lib is not processing the image if the size stays the same. Looks like it is has no check, so it wastes CPU-Time.
Possible Fix in TransformationZoom: check if self.percent == 100 and just return the image:
class TransformationZoom(BaseTransformation):
name = 'zoom'
arguments = ('percent',)
label = _('Zoom')
def execute_on(self, *args, **kwargs):
super(TransformationZoom, self).execute_on(*args, **kwargs)
+ if self.percent == 100:
+ return self.image
decimal_value = float(self.percent) / 100
return self.image.resize(
(
int(self.image.size[0] * decimal_value),
int(self.image.size[1] * decimal_value)
), Image.ANTIALIAS
)