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

Fix #4: Change masked layer size to same as other channels #5

Merged
merged 1 commit into from
Aug 29, 2017

Conversation

mdboom
Copy link
Owner

@mdboom mdboom commented Aug 17, 2017

The masked channel in a layer does not have to be the same size as the other channels. That gets pretty inconvenient to work with, so when using the "user-friendly" interface in user.nested_layers, the masked channel will now get forcibly cropped/extended to the same size as the other channels.

With this change, it should be possible to make a PNG that applies the masked layer as follows:

import pytoshop
from pytoshop.user import nested_layers
import numpy as np
from PIL import Image

psdfile = pytoshop.read(open("masked_layer.psd", 'rb'))

layers = nested_layers.psd_to_nested_layers(psdfile)

l = layers[0]

a = np.array(l.channels[-1].image * (l.channels[-2].image / 255), np.uint8)
rgba = np.dstack(
    [l.channels[0].image, l.channels[1].image, l.channels[2].image, a]
)

im = Image.fromarray(rgba)
im.save('test.png')

@codecov-io
Copy link

codecov-io commented Aug 17, 2017

Codecov Report

Merging #5 into master will increase coverage by 0.15%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #5      +/-   ##
==========================================
+ Coverage   89.66%   89.82%   +0.15%     
==========================================
  Files          14       14              
  Lines        3067     3085      +18     
==========================================
+ Hits         2750     2771      +21     
+ Misses        317      314       -3
Impacted Files Coverage Δ
pytoshop/user/nested_layers.py 90.36% <100%> (+1.11%) ⬆️
pytoshop/layers.py 89.88% <0%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8eec8e...757e1ab. Read the comment docs.

@mdboom mdboom merged commit 81e1c20 into master Aug 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants