Image crop+compose issue

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
vmahendra

Image crop+compose issue

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Image crop+compose issue

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply