[magick-users] composite Dst_In transparency problem

Anthony Thyssen anthony at griffith.edu.au
Mon Sep 18 22:11:33 CDT 2006


=?iso-8859-1?Q?G=FCnter?= Bachelier on  wrote...
| Hello,
|
| I have a problem concerning composite: after the composing with
| Dst_In the parts that were transparent in the mask were in the
| result image black:
|
| convert -size $triangle_widthx$triangle_width -stroke red -fill red
| -draw "polyline 1,1 $triangle_width,$triangle_width 1,$triangle_width"
| xc:none p4m_mask.png
| convert -crop $triangle_widthx$triangle_width+$x4+$y4 image.jp2
| image_p4m.png
| composite p4m_mask.png image_p4m.png -compose Dst_In p4m_G1.png
|
| A correction of the result with "-transparent black" would change all
| parts.
| How can the transparency be preserved?
|
| Perhaps "-clip-mask" could be used, but I did not find a dokumentation
| that helped me.
|
Hmmm..  Okay lets pick this apart, remove variables and simplify...

NOTE:  $triangle_widthx$triangle_width
should read   ${triangle_width}x$triangle_width
as I am sure $triangle_widthx is an undefined variable!!!!!

-stroke by default is 'none' and as you are filling you don't need it.
And as you are using a mask, you don't even need color!!!!

And create a canvas before you try drawing on it.

Note if you have an image sized 100,  pixel positions are from 0 to 99
not 1 to 100.

   convert -size 100x100 xc:none -fill red \
           -draw "polyline 0,0 99,99 0,99"  p4m_mask.png

I''l use granite: for the test image, again read then crop.
and remove any page offsets from the crop.

   convert granite: -crop 100x100+10+10 +repage image_p4m.png

Now for the composite.  Make sure your destination image has an alpha
channel, especially important if you source is JPEG which has no
transparency.

   composite p4m_mask.png image_p4m.png -matte -compose Dst_In p4m_G1.png

no problem image masked correctly...

Lets finish by doing all this in ONE command (swap Dst and Scr order for
the "convert" use of -composite

  convert granite: -crop 100x100+10+10 +repage -matte \
          \( -size 100x100 xc:none -draw "polyline 0,0 99,99 0,99" \) \
          -compose Dst_In -composite  p4m_G1.png

I'll leave it to you to re-add your variables.

NOTE: The above will be a different result to using masks to replace the
alpha channel of the input image using "-compose CopyOpacity".   If the
source image already has an alpha channel, the above only adds to that
alpha channel, making more parts transparent.  The above is in fact the
better technique, than using masks.

I suggest you read the various sections of IM Examples thoughly
and check the results of each operation, piece by piece.

Also  -clip-mask  is a new special setting which limits any future
operators to a specific region of the image. It does not add
transparency to an image.  Of course inverting that mask, then erasing
everything will have a simular result :-)


  Anthony Thyssen ( System Programmer )    <A.Thyssen at griffith.edu.au>
 -----------------------------------------------------------------------------
  Ralph's Observation:
          It is a mistake to allow any mechanical object to
                   realize that you are in a hurry.
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.cit.gu.edu.au/~anthony/


More information about the Magick-users mailing list