-draw image DstIn cropping problem

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?".
Locked
Marcel71
Posts: 50
Joined: 2011-04-13T13:57:34-07:00
Authentication code: 8675308

-draw image DstIn cropping problem

Post 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

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -draw image DstIn cropping problem

Post 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

Locked