Page 1 of 1

Create white rectangle with transparent cutout on transparent BG

Posted: 2017-04-04T02:09:08-07:00
by Duwgati
I need to create a PNG like this: (www.duwgati.nl/product-mask.jpg)
Image

I have managed to create this image except for the transparent cutout: (www.duwgati.nl/product-mask.png)
Image
As you can see, it creates the transparent "cutout" on the white rectangle, so that doesn't seem to be the right approach for my needs.

So how can I achieve my goal?

P.S. This is the code I have used:
exec('c:\\imagemagick\\convert.exe -size 255x479 xc:white -fill "rgba(255, 215, 0, 0.1)" -draw "roundrectangle 20,20 235,459 20,20" PNG32:test/rectangle.png');

exec('c:\\imagemagick\\convert.exe -size 1366x768 xc:"rgba(0,0,0,0)" PNG32:test/test.png');

exec('c:\\imagemagick\\convert.exe -size 1366x768 xc:"rgba(0,0,0,0)" -gravity center -draw "image over 0,0 0,0 test/rectangle.png" PNG32:test/product-mask.png');

Re: Create white rectangle with transparent cutout on transparent BG

Posted: 2017-04-04T05:20:12-07:00
by Duwgati
I found the solution myself:

exec('c:\imagemagick\convert.exe -size 1366x768 xc:"rgba(255,215,0,0)" -fill white -draw "rectangle 555,143 811,625" \(-size 216,442 xc:none -fill black -draw "roundrectangle 575,163 791,605 25,25"\) -alpha Set -compose Dst_Out -composite test/product-mask.png ');

Re: Create white rectangle with transparent cutout on transparent BG

Posted: 2017-04-04T16:13:46-07:00
by snibgo
There are many ways of doing this. For example, we can build an image that is black where the output should be transparent, and white where the output should be opaque. Then we make a clone, turn this white, and CopyOpacity to it. Windows BAT script.

Code: Select all

%IM%convert ^
  -size 1366x768 xc:Black ^
  -fill White -draw "rectangle 555,144 810,623" ^
  -fill Black -draw "roundrectangle 575,164 790,603 20,20" ^
  ( +clone -fill White -colorize 100 ) ^
  +swap ^
  -alpha off ^
  -compose CopyOpacity -composite ^
  out.png