Hi,
I want to crop a png image into two png images like
How to get the tow images in command line?
Any help appreciated, thanks a lot !
Crop image into a circle
-
- Posts: 2
- Joined: 2016-09-15T23:54:35-07:00
- Authentication code: 1151
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Crop image into a circle
IMPORTANT: To get the best help you should always let us know which version of ImageMagick you're using and which OS you're working on. That can make a big difference in the actual commands you'll use.YujianPeng wrote:I want to crop a png image into two png images like [...] How to get the tow images in command line?
One way to get a transparent hole is to make a clone of your input image, change that clone to transparent, draw a white circle on it where you want the hole to be, and composite it on your input image using the "DstOut" method. Here is a command using Windows syntax that should work with recent versions of IM6 (convert) or IM7 (magick)...
Code: Select all
convert 3-sample.png -alpha on -background none ^
( +clone -channel A -evaluate multiply 0 +channel -fill white -draw "ellipse 153,128 57,57 0,360" ) ^
-compose DstOut -composite circle_out.png
Code: Select all
convert 3-sample.png -alpha on -background none ^
( +clone -channel a -evaluate multiply 0 +channel -fill white -draw "ellipse 153,128 57,57 0,360" ) ^
-compose DstIn -composite circle_in.png
To do both of these operations in a single command, you'd start with the input image, make the transparent clone, and put the circle where you want it. Composite them twice, once using the compose method "DstOut" and another time using "DstIn". At that point you have all four images in the stack, so you "-delete" the first and second images which are the input and the mask. That leaves your two modified images which will be the output. That command would look something like this...
Code: Select all
convert 3-sample.png -alpha on -background none ^
( +clone -channel A -evaluate multiply 0 +channel -fill white -draw "ellipse 153,128 57,57 0,360" ) ^
( -clone 0,1 -compose DstOut -composite ) ^
( -clone 0,1 -compose DstIn -composite ) ^
-delete 0,1 circle.png
To change these commands to *nix shell syntax you'll need to replace the continued line carets "^" with backslashes "\" and use backslashes to escape the parentheses like "\(" and "\)". You may also have to tweak another thing or two like change the double quote marks to single quotes.
-
- Posts: 2
- Joined: 2016-09-15T23:54:35-07:00
- Authentication code: 1151
Re: Crop image into a circle
GeeMack, Thanks for your reply. Your commands work very good for me!
Thanks a lot!
Thanks a lot!