Skip to content

Commit

Permalink
Fix for alpha preservation in ImageEnhance, #899
Browse files Browse the repository at this point in the history
  • Loading branch information
wiredfool committed Sep 18, 2014
1 parent 5ea966d commit 394f6d3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion PIL/ImageEnhance.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ class Color(_Enhance):
"""
def __init__(self, image):
self.image = image
self.degenerate = image.convert("L").convert(image.mode)
self.intermediate_mode = 'L'
if 'A' in image.getbands():
self.intermediate_mode = 'LA'

self.degenerate = image.convert(self.intermediate_mode).convert(image.mode)

class Contrast(_Enhance):
"""Adjust image contrast.
Expand All @@ -62,6 +65,9 @@ def __init__(self, image):
mean = int(ImageStat.Stat(image.convert("L")).mean[0] + 0.5)
self.degenerate = Image.new("L", image.size, mean).convert(image.mode)

if 'A' in image.getbands():
self.degenerate.putalpha(image.split()[-1])


class Brightness(_Enhance):
"""Adjust image brightness.
Expand All @@ -74,6 +80,9 @@ def __init__(self, image):
self.image = image
self.degenerate = Image.new(image.mode, image.size, 0)

if 'A' in image.getbands():
self.degenerate.putalpha(image.split()[-1])


class Sharpness(_Enhance):
"""Adjust image sharpness.
Expand All @@ -85,3 +94,6 @@ class Sharpness(_Enhance):
def __init__(self, image):
self.image = image
self.degenerate = image.filter(ImageFilter.SMOOTH)

if 'A' in image.getbands():
self.degenerate.putalpha(image.split()[-1])

0 comments on commit 394f6d3

Please sign in to comment.