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?".

cropping an image according to its shape

Postby sin » 2011-05-08T05:57:26+00:00

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=http://www.lucylearns.com/images/christmas-black-and-white-clipart-free-christmas-clipart-christmas-clipart-graphic-clipart-black-white-free-christmas-tree-clipart-1med.gif&imgrefurl=http://www.lucylearns.com/christmas-tree-clipart.html&usg=__8ImK_Giz5D_XBoknEES7kUcx_go=&h=228&w=200&sz=3&hl=en&start=2&zoom=1&tbnid=R6zB2gUicJzyyM:&tbnh=108&tbnw=95&ei=co3GTdapG8errAfxkJTsBA&prev=/search%3Fq%3Dtree%2Bclipart%26hl%3Den%26gbv%3D2%26biw%3D1297%26bih%3D683%26tbm%3Disch&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.
sin
 
Posts: 46
Joined: 2011-04-23T11:06:13+00:00

Re: cropping an image according to its shape

Postby fmw42 » 2011-05-08T10:51:52+00:00

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
User avatar
fmw42
 
Posts: 14785
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA


Return to Users

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot], Yahoo [Bot] and 19 guests