Page 1 of 1

Image crop+compose issue

Posted: 2009-06-08T01:31:18-07:00
by vmahendra
that what i wanna to do IM for me

1) I have square piece of an image as source Image let say 800px X 800px.
2) I have an stencil (Suppose a triangle image size say as 100px X 100 px)
3) I have x and y co-ordinate say as x=25px and y=20px

Now what IM should do as first it take source image put the triangle stencil on it BUT the triangle image should be imposed on source image at x=25 and y=20 position.

And finally it cut the triangle stencil containing square's(source image) background.

Pl help me ASAP.

warm regards
Mahendra Varandani

Re: Image crop+compose issue

Posted: 2009-06-08T03:12:55-07:00
by anthony
How is the triangle stencil image defined?
  • White on Black,
  • Black on White,
  • some shape with a transparent triangular hole,
  • or a triangle surrounding by transparency
The compose operation you use depends on the above and what part you want 'cut out' or layered over.
Their are about 8 posibilities depending on the form of the stencil, and the result wanted!
See http://www.imagemagick.org/Usage/compose/#duff-porter
Which has a table for ones involving transparency
otherwise it is either CopyOpacity (cut out) Multiply (white transparent) Screen (black transparent)

From your Text however I think you just want 'over' Assuming the triangle stencil is already the right color. Otherwise color it using -colorize!
See Using Masks as Colored Shapes -- which I believe is what you are looking for.
http://www.imagemagick.org/Usage/channels/#shapes

As for the crop. You can either do that before, or after the compose. Better before as then their is less work for the compose operation.

Code: Select all

convert  {source_image}  -crop 100x100+25+20 +repage \
         \( stencil_image -fill {color_desired} -colorize 100% \) \
         -compose  Over  -composite \
         {result_image}
Replace the {..} parts as required.