I need to create a PNG like this: (www.duwgati.nl/product-mask.jpg)
I have managed to create this image except for the transparent cutout: (www.duwgati.nl/product-mask.png)
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');
Create white rectangle with transparent cutout on transparent BG
Re: Create white rectangle with transparent cutout on transparent BG
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 ');
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 ');
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Create white rectangle with transparent cutout on transparent BG
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
snibgo's IM pages: im.snibgo.com