Page 1 of 1

-draw image DstIn cropping problem

Posted: 2020-05-05T16:14:30-07:00
by Marcel71
Hi,

I am on Ubuntu 18.04 with IM version 7.0.10-9
I am having a problem using the -draw option combined with DstIn that the resulting image is not being cropped.

text_1.png:
Image

example_image.png
Image

When I run the following command I would expect only to get the DstIn area:

Code: Select all

magick example_image.png  -alpha set -draw "image DstIn 0,0 0,0 'text_1.png' " out1.png
Result:
Image

When I run the next command I get the desired result:

Code: Select all

magick example_image.png  -alpha set text_1.png -compose DstIn -composite out2.png
Result:
Image

However, with the last command I can not position the mask like:

Code: Select all

magick example_image.png  -alpha set -draw "image DstIn -100,-100 0,0 'text_1.png' " out3.png
Result:
Image

Anybody know how to only have the resulting area where which the two images share?
It should be like:
Image

Regards,
Marcel

Re: -draw image DstIn cropping problem

Posted: 2020-05-05T16:57:05-07:00
by fmw42
IM 6 transparency is handled a bit differently from IM 6. The main issue is that the two images need to be the same size.

This is one way to do what you want for an offset of 50,50. Get the dimensions of the large image. Then extent the smaller image to the same size with and offset. Note that in -extent, the offsets are the opposite polarity, so negative values, then save that result in an MPR: in-memory file and delete the parentheses processed version. Then use the MPR: image in the -draw with no offers.

Code: Select all

magick example_image.png -set option:dims "%wx%h" \
\( text_1.png -background none -extent "%[dims]-50-50" -write mpr:text1 +delete \) \
-alpha set -draw "image DstIn 0,0 0,0 'mpr:text1' " out3.png