wvanbergen / chunky_png

Read/write access to PNG images in pure Ruby.
https://chunkypng.com
MIT License
1.05k stars 101 forks source link

Add apply_as_mask operation #68

Closed wooly closed 10 years ago

wooly commented 10 years ago

I had a need for an operator like this when I wanted to apply a circular layer mask to an image. I thought it might be useful for others too!

Starting with an image, you create a canvas of the same size with a white background. Then you 'colour in' bits of the new canvas black. Use mask.apply_as_image(image) to modify the mask replacing all black pixels with their respective image pixels.

wvanbergen commented 10 years ago

Looks good, two comments. Also, can you add a spec for this method?

wooly commented 10 years ago

I've added a few specs, and changed the interface so we have apply_mask and apply_mask! methods. Unfortunately, my attempt to hack together the masked.png reference image didn't work, so the two specs that really matter won't work. Would you be able to take a look, @wvanbergen?

wvanbergen commented 10 years ago

I'm on vacation; it'll take a while before I can look at this.

Sent from my iPhone

On Jul 8, 2014, at 16:50, Steve Bell notifications@github.com wrote:

I've added a few specs, and changed the interface so we have apply_mask and apply_mask! methods. Unfortunately, my attempt to hack together the masked.png reference image didn't work, so the two specs that really matter won't work. Would you be able to take a look, @wvanbergen?

— Reply to this email directly or view it on GitHub.

wvanbergen commented 10 years ago

Closing this stale branch; you can already perform an operation like this using the well tested compose method, and I'd like to keep the scope and complexity of this library relatively small.