From e38ff20adaae91d8e7fa436c85d9c1a710b2ff26 Mon Sep 17 00:00:00 2001 From: David Fischer Date: Wed, 21 Nov 2018 11:29:19 +0100 Subject: [PATCH] Release 13.0.3 --- changelog.rst | 12 ++---------- pytoolbox/__init__.py | 2 +- pytoolbox/multimedia/image/PIL.py | 15 ++++++--------- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/changelog.rst b/changelog.rst index ccdf5624..7349b1d0 100644 --- a/changelog.rst +++ b/changelog.rst @@ -3,22 +3,14 @@ changelog ========= ------- -v13.0.2 -------- - -Fix and enhancements -==================== - -* Function multimedia.image.remove_transparency: Add force_rgb argument + enhance code. - -------- -v13.0.1 +v13.0.3 ------- Fix and enhancements ==================== * Function aws.s3.remove_objects: Add callback argument to make it more flexible. +* Function multimedia.image.remove_transparency: Enhance code (remove force_rgb arg from 13.0.2). ------- v13.0.0 diff --git a/pytoolbox/__init__.py b/pytoolbox/__init__.py index 91821e38..53cfd974 100644 --- a/pytoolbox/__init__.py +++ b/pytoolbox/__init__.py @@ -2,4 +2,4 @@ from __future__ import absolute_import, division, print_function, unicode_literals -__version__ = '13.0.2' +__version__ = '13.0.3' diff --git a/pytoolbox/multimedia/image/PIL.py b/pytoolbox/multimedia/image/PIL.py index 79c993ee..e75eca3f 100644 --- a/pytoolbox/multimedia/image/PIL.py +++ b/pytoolbox/multimedia/image/PIL.py @@ -55,19 +55,16 @@ def remove_metadata(image, keys=('exif', ), inplace=False): return image -def remove_transparency(image, background=(255, 255, 255), force_rgb=False): +def remove_transparency(image, background=(255, 255, 255)): """ Return a RGB image with an alpha mask applied to picture + background. - If alpha not found, then convert to RGB if forced else do nothing. + If image is already in RGB, then its a no-op. """ - try: - alpha = image.getchannel('A') - except ValueError as e: - if 'has no channel' in str(e): - return image.convert('RGB') if force_rgb else image - raise + if image.mode == 'RGB': + return image # No-op + alpha = image.convert('RGBA').getchannel('A') new_image = Image.new('RGB', image.size, background) - new_image.paste(image, mask=alpha) + new_image.paste(image.convert('RGB'), mask=alpha) return new_image