cropping an image according to its shape

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
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

cropping an image according to its shape

Post by sin »

hi,

please tell me how can i crop an image according to its shape and the remaining white spaces should not be there in the image? for example, if we take the following image as an example

http://www.google.co.in/imgres?imgurl=h ... sch&itbs=1

i want only the image of the outline of the tree. the space around the outline should not be there in the output image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: cropping an image according to its shape

Post by fmw42 »

I am not sure exactly what you want, so here are two options.


1) This will fill everything white as transparent and leave the black:

convert christmas-black-and-white.gif -fuzz 1% -transparent white tmp1.gif

2) This will fill only the outside white as transparent and leave the inside white alone.

convert christmas-black-and-white.gif -bordercolor white -border 10 -fuzz 1% -fill none \
-draw "matte 0,0 floodfill" -shave 10x10 tmp2.png

or

convert christmas-black-and-white.gif -bordercolor white -border 10x10 \
-alpha set -channel rgba -fuzz 1% -fill none \
-floodfill +0+0 white -shave 10x10 tmp3.png


there seems to be some error in writing to gif so I used png in the latter two cases as with gif, the interior was cyan and not white. I will report this error. see viewtopic.php?f=3&t=18705

IM 6.6.9.8 Q16 Mac OSX Tiger


see
http://www.imagemagick.org/script/comma ... ransparent
http://www.imagemagick.org/script/comma ... s.php#fuzz
http://www.imagemagick.org/Usage/draw/#matte
http://www.imagemagick.org/Usage/masking/#floodfill
Post Reply