Crop with PNG on PNG [resolved]

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
weblife
Posts: 21
Joined: 2016-01-06T22:23:33-07:00
Authentication code: 1151

Crop with PNG on PNG [resolved]

Post by weblife »

Anyone have a suggestion for how I can alter the following command to crop one PNG with another PNG?

Code: Select all

convert artwork.png alpha.png -gravity Center -alpha Off -compose copy_opacity -composite out.png
Currently the issue I am seeing is on my existing PNG image a black block appears where another PNG was placed to a transparent canvas.

Image + Image = Image

My Version: ImageMagick 6.9.1-10 Q16 x86_64 2015-07-26
Platform: Mac OSX El Capitan 10.11.6
Last edited by weblife on 2016-09-15T17:45:02-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop with PNG on PNG

Post by fmw42 »

What is your IM version and platform? Please always provide that.
weblife
Posts: 21
Joined: 2016-01-06T22:23:33-07:00
Authentication code: 1151

Re: Crop with PNG on PNG

Post by weblife »

Placed platform in above also. Sorry.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop with PNG on PNG

Post by fmw42 »

try

Code: Select all

convert \( artwork.png -alpha extract \)  alpha.png -gravity Center -alpha Off -compose copy_opacity -composite out.png
Is this what you want.

Your problem is that your artwork image has the detail in the alpha channel and not the base image. So you need to extract the detail from the alpha channel of artwork and use that.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop with PNG on PNG

Post by fmw42 »

Or perhaps you want this with the polarity switched in the artwork texture.

Code: Select all

convert \( artwork.png -alpha extract -negate \)  alpha.png -gravity Center -alpha Off -compose copy_opacity -composite out2.png
weblife
Posts: 21
Joined: 2016-01-06T22:23:33-07:00
Authentication code: 1151

Re: Crop with PNG on PNG

Post by weblife »

Thank you Fred. Much closer. The second output is closer to what I am looking to do "out2.png". I was able to achieve that with flatten :

Code: Select all

convert artwork.png -flatten alpha.png -gravity Center -alpha Off -compose copy_opacity -composite png:out.png 
I want to keep the white area transparent also. Need to see if I alter my alpha.png white to transparent will achieve this.
weblife
Posts: 21
Joined: 2016-01-06T22:23:33-07:00
Authentication code: 1151

Re: Crop with PNG on PNG

Post by weblife »

I should clarify. I want to keep the transparent area transparent from "artwork.png".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop with PNG on PNG

Post by fmw42 »

You will need to separate the alpha channels and then multiply them (possibly with one negated), then use the combined alpha channel and put that back on the image.

Note that transparent means the alpha channel will be black in those areas, not white.
weblife
Posts: 21
Joined: 2016-01-06T22:23:33-07:00
Authentication code: 1151

Re: Crop with PNG on PNG

Post by weblife »

Okay, here is what I did to achieve:

Code: Select all

convert \( artwork.png -gravity center -extent 2000x2000 -fuzz 9% -transparent white \) \
alpha.png -gravity center -alpha On -compose copy_opacity \
-composite -fuzz 9% -transparent white altered.png
Post Reply