cut and keep remainder
cut and keep remainder
I have a question about how to cut an image and keep the remainder and not what was cut. So for instance I have an image that is 1024x200. I want cut out a section that is 700x150 and discard that piece and keep the piece with a cut out. I haven't been able to find this anywhere? Thanks in advance.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: cut and keep remainder
You basically have to fill the region in the middle with transparency. Here are two ways.
This one works in general. Create a white image the size of the input (using +clone -threshold -1), insert a black area where you want the hole, then copy that to the alpha channel.
convert logo: \( +clone -threshold -1 -size 100x100 xc:black -gravity center -composite \) -compose copy_opacity -composite logo_hole1.png
This one works if you have no black in your image. You can choose some other color that is not in your image.
So you composite a black image the size of the hole onto your image and then make that color (black) into transparency.
convert logo: -size 100x100 xc:black -gravity center -composite -transparent black logo_hole2.png
I am sure there are other ways to do this. But these two come to mind.
The logo: image is an IM internal test image. You can substitute your image for it. See http://www.imagemagick.org/script/forma ... tin-images
You need to use either GIF or PNG for your output as they two formats support transparency. JPG does not.
See masking and transparency at http://www.imagemagick.org/Usage/channels/
This one works in general. Create a white image the size of the input (using +clone -threshold -1), insert a black area where you want the hole, then copy that to the alpha channel.
convert logo: \( +clone -threshold -1 -size 100x100 xc:black -gravity center -composite \) -compose copy_opacity -composite logo_hole1.png
This one works if you have no black in your image. You can choose some other color that is not in your image.
So you composite a black image the size of the hole onto your image and then make that color (black) into transparency.
convert logo: -size 100x100 xc:black -gravity center -composite -transparent black logo_hole2.png
I am sure there are other ways to do this. But these two come to mind.
The logo: image is an IM internal test image. You can substitute your image for it. See http://www.imagemagick.org/script/forma ... tin-images
You need to use either GIF or PNG for your output as they two formats support transparency. JPG does not.
See masking and transparency at http://www.imagemagick.org/Usage/channels/
Re: cut and keep remainder
fmw42 - that is EXACTLY what I needed - thank you thank you thank you. Spent 3 hours scouring last night (went through a bottle of wine which probably didn't help) but you have given me exactly what I needed. PERFECTO.
Hope I can someday return the fav.
Hans
Hope I can someday return the fav.
Hans
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: cut and keep remainder
you are welcome. glad it helped
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: cut and keep remainder
Their are two ways of specifying the part of the image you do not want, (or do want) One method is to use a gray scale (mostly black and white) mask, and using 'CopyOpacity'. The other is an alpha channel shape, and use 'DstIn' and 'DstOut' as appropriate.
See IM Examples, Composing, as well as Channel, Masks, and Transparency
http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/channels/
See IM Examples, Composing, as well as Channel, Masks, and Transparency
http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/channels/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/