Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.8.23 #123

Merged
merged 6 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
1.8.23 (2019-06-24)
-------------------

- [composer] fix clipping on alpha-less image;
- [composer] fix stroke effect for flat plane;
- [composer] workaround for insufficient knots;
- [composer] fix for custom color space.

1.8.22 (2019-06-19)
-------------------

Expand Down
8 changes: 6 additions & 2 deletions src/psd_tools/composer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ def compose_layer(layer, force=False, **kwargs):
clip_image = compose(
layer.clip_layers, bbox=bbox, context=image.copy()
)
mask = image.getchannel('A')
if image.mode.endswith('A'):
mask = image.getchannel('A')
else:
mask = Image.new('L', image.size, 255)
if clip_image.mode.endswith('A'):
mask = ImageChops.darker(clip_image.getchannel('A'), mask)
clip_image.putalpha(mask)
Expand Down Expand Up @@ -332,6 +335,7 @@ def apply_effect(layer, backdrop, base_image):
else:
alpha = base_image.convert('L')
alpha.info['offset'] = base_image.info['offset']
flat = alpha.getextrema()[0] < 255

# Expand the image size
setting = effect.value
Expand All @@ -345,7 +349,7 @@ def apply_effect(layer, backdrop, base_image):

if not layer.has_vector_mask() and setting.get(
Key.Style
).enum == Enum.InsetFrame:
).enum == Enum.InsetFrame and flat:
image = create_stroke_effect(alpha, setting, layer._psd, True)
backdrop.paste(image)
else:
Expand Down
12 changes: 10 additions & 2 deletions src/psd_tools/composer/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def _draw_subpath(subpath, width, height):
from PIL import Image
import aggdraw
mask = Image.new('L', (width, height), 0)
if len(subpath) <= 1:
logger.warning('not enough knots: %d' % len(subpath))
return mask
path = ' '.join(map(str, _generate_symbol(subpath, width, height)))
draw = aggdraw.Draw(mask)
brush = aggdraw.Brush(255)
Expand Down Expand Up @@ -156,7 +159,7 @@ def draw_solid_color_fill(size, setting):
from PIL import Image, ImageDraw, ImageChops
color = setting.get(Key.Color)
mode = _COLORSPACE.get(color.classID)
fill = tuple(int(x) for x in color.values())
fill = tuple(int(x) for x in list(color.values())[:len(mode)])
canvas = Image.new(mode, size)
draw = ImageDraw.Draw(canvas)
draw.rectangle((0, 0, canvas.width, canvas.height), fill=fill)
Expand Down Expand Up @@ -230,6 +233,10 @@ def draw_gradient_fill(size, setting):
Z = _make_reflected_gradient(X, Y, angle)
elif gradient_kind == Enum.Diamond:
Z = _make_diamond_gradient(X, Y, angle)
elif gradient_kind == b'shapeburst':
# Only available in stroke effect.
logger.warning('Gradient style not supported: %s' % gradient_kind)
Z = np.ones((size[1], size[0])) * 0.5
else:
logger.warning('Unknown gradient style: %s.' % (gradient_kind))
Z = np.ones((size[1], size[0])) * 0.5
Expand Down Expand Up @@ -341,7 +348,8 @@ def _apply_color_map(grad, Z):
mode = _COLORSPACE.get(stop.get(Key.Color).classID)
s = scalar.get(mode, 1.0)
location = int(stop.get(Key.Location)) / 4096.
color = tuple(s * x for x in stop.get(Key.Color).values())
color = list(stop.get(Key.Color).values())[:len(mode)]
color = tuple(s * int(x) for x in color)
if len(X) and X[-1] == location:
logger.debug('Duplicate stop at %d' % location)
X.pop(), Y.pop()
Expand Down
2 changes: 1 addition & 1 deletion src/psd_tools/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.8.22'
__version__ = '1.8.23'