Given a PNG filled with color, how do I clear the top left corner so that it's just transparent? I can achieve this in MacOS's Preview by selecting an area and pressing delete.
What I imagined would work - convert 3.png -strokewidth 0 -fill transparent -draw "rectangle 0,0 30,30 " output.png
Version: ImageMagick 6.9.9-40 Q16 x86_64 2019-08-07
Want to clear a corner of a PNG
-
- Posts: 2
- Joined: 2019-08-07T16:27:03-07:00
- Authentication code: 1152
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Want to clear a corner of a PNG
One way is to clone the image, make it completely white, then draw a black region and then put that into the alpha channel of the input.
Another way is to use -region:
A third way is to draw a rectangle of some opaque color not in (that part of) the image, then flood fill that color with transparency.
Code: Select all
convert logo: \
\( +clone -fill white -colorize 100 \
-fill black -draw "rectangle 0,0 99,99" \) \
-alpha off -compose copy_opacity -composite \
result.png
Code: Select all
convert logo: -alpha set -region 100x100+0+0 -alpha transparent +region result.png
Code: Select all
convert logo: \
-fill black -draw "rectangle 0,0 99,99" -alpha off \
-fill none -draw "matte 0,0 floodfill" \
result.png
-
- Posts: 2
- Joined: 2019-08-07T16:27:03-07:00
- Authentication code: 1152
Re: Want to clear a corner of a PNG
The region method works perfectly, thank you!