Skip to content

Commit

Permalink
Release 13.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfischer-ch committed Nov 21, 2018
1 parent 7f15820 commit e38ff20
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
12 changes: 2 additions & 10 deletions changelog.rst
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pytoolbox/__init__.py
Expand Up @@ -2,4 +2,4 @@

from __future__ import absolute_import, division, print_function, unicode_literals

__version__ = '13.0.2'
__version__ = '13.0.3'
15 changes: 6 additions & 9 deletions pytoolbox/multimedia/image/PIL.py
Expand Up @@ -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


Expand Down

0 comments on commit e38ff20

Please sign in to comment.