Making corners of an image transparent
Making corners of an image transparent
I have a bunch of jpg's that I would like to convert to png's and also make their corners transparent. That is, I want the images to look like someone cut off the corners.
So, I though perhaps I could use an overlay. However, I assume that if I set say a white image with the transparent corners as the background and overlay the new image, it won't work. And obviously I can't use the original as the background and then overlay transparentness, or can i?
Other suggestions?
TIA,
drue
So, I though perhaps I could use an overlay. However, I assume that if I set say a white image with the transparent corners as the background and overlay the new image, it won't work. And obviously I can't use the original as the background and then overlay transparentness, or can i?
Other suggestions?
TIA,
drue
Re: Making corners of an image transparent
Is this the sort of effect you want - this code creates a rounded rectangle and uses that to cut the corners. You can use other shapes for the mask.
Code: Select all
convert -size 637x140 xc:none -fill white-draw "roundRectangle 0,0 637,140 15,15" albir.jpg -compose SrcIn -composite rounded_corners.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Making corners of an image transparent
Not sure what you really want. But you can mask the corners to transparent or draw transparent boxes at the corners.
Make a white image and overlay small black images in its corner where you want it to be transparent. Then use that as an alpha channel for your image.
convert -size 128x128 xc:white white.png
convert -size 16x16 xc:black black.png
convert white.png \
black.png -gravity northwest -compose over -composite \
black.png -gravity northeast -compose over -composite \
black.png -gravity southeast -compose over -composite \
black.png -gravity southwest -compose over -composite \
mask.png
convert zelda3.png mask.png -compose copy_opacity -composite zelda3_corners.png
Make a white image and overlay small black images in its corner where you want it to be transparent. Then use that as an alpha channel for your image.
convert -size 128x128 xc:white white.png
convert -size 16x16 xc:black black.png
convert white.png \
black.png -gravity northwest -compose over -composite \
black.png -gravity northeast -compose over -composite \
black.png -gravity southeast -compose over -composite \
black.png -gravity southwest -compose over -composite \
mask.png
convert zelda3.png mask.png -compose copy_opacity -composite zelda3_corners.png
Re: Making corners of an image transparent
*blush*, ok, this is pretty geeky, but here's what I'm aiming for:
becomes something like this, except those corners are of course transparent, not just white:
becomes something like this, except those corners are of course transparent, not just white:
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Making corners of an image transparent
You can draw one big polygon filled white with black or transparent on the outside like Bonzo did with his rounded corner or you can make one small square image like I did, but make diagonally half black and half white (you will have to use -draw to make the triangular sections) and then composite as I did in the corners on a white image to make the alpha channel.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Making corners of an image transparent
Make sure you enable the alpha channel if using Alpha composition.
However if using CopyOpacity make sure to turn it off (or it copies a opaque alpha rather than the grayscale mask).
A similar method is detailed in IM Examples. Thumbnails, Rounded Corners, the only difference between that and what you want is the shape of the drawn mask being used.
However if using CopyOpacity make sure to turn it off (or it copies a opaque alpha rather than the grayscale mask).
A similar method is detailed in IM Examples. Thumbnails, Rounded Corners, the only difference between that and what you want is the shape of the drawn mask being used.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Making corners of an image transparent
Here is my triangle drawing on a square for the corner method:
convert -respect-parenthesis \( -size 128x128 xc:white \) \
\( -size 16x16 xc:black -fill white -draw "polygon 0,0 0,15 15,15" -write mpr:triangle +delete \) \
mpr:triangle -gravity northeast -compose over -composite \
\( mpr:triangle -rotate 90 \) -gravity southeast -compose over -composite \
\( mpr:triangle -rotate 180 \) -gravity southwest -compose over -composite \
\( mpr:triangle -rotate -90 \) -gravity northwest -compose over -composite \
zelda3.jpg +swap -compose copy_opacity -composite \
zelda3_corners2.png
However, it may be easier/quicker to just find the polygon you want and draw one mask.
convert -respect-parenthesis \( -size 128x128 xc:white \) \
\( -size 16x16 xc:black -fill white -draw "polygon 0,0 0,15 15,15" -write mpr:triangle +delete \) \
mpr:triangle -gravity northeast -compose over -composite \
\( mpr:triangle -rotate 90 \) -gravity southeast -compose over -composite \
\( mpr:triangle -rotate 180 \) -gravity southwest -compose over -composite \
\( mpr:triangle -rotate -90 \) -gravity northwest -compose over -composite \
zelda3.jpg +swap -compose copy_opacity -composite \
zelda3_corners2.png
However, it may be easier/quicker to just find the polygon you want and draw one mask.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Making corners of an image transparent
No need to create a large mask, if you use a transparent background you can alpha compose
the corners directly on the main image. this way you don't even need to know the images size!
I have added it to the rounded corner thumbnail examples
http://www.imagemagick.org/Usage/thumbnails/#rounded
It will appear in an hour or so.
the corners directly on the main image. this way you don't even need to know the images size!
Code: Select all
convert thumbnail.gif -alpha set -compose DstOut \
\( -size 20x10 xc:none -draw "polygon 0,0 0,9 19,0" \
-write mpr:triangle +delete \) \
\( mpr:triangle \) -gravity northwest -composite \
\( mpr:triangle -flip \) -gravity southwest -composite \
\( mpr:triangle -flop \) -gravity northeast -composite \
\( mpr:triangle -rotate 180 \) -gravity southeast -composite \
corner_cutoff.png
I have added it to the rounded corner thumbnail examples
http://www.imagemagick.org/Usage/thumbnails/#rounded
It will appear in an hour or so.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Making corners of an image transparent
Wow. I am just floored by everyone's level of support and helpfulness here. Thank you so much, it's perfect. I had to update imagemagick to pick up -alpha, but it wasn't too bad.
drue
drue
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Making corners of an image transparent
-matte will do the same job as -alpha set and has been around as long as I can remember.
The -alpha method is the newer one that expands the role of the older option with lots more options
see http://www.imagemagick.org/Usage/basics/#alpha
The -alpha method is the newer one that expands the role of the older option with lots more options
see http://www.imagemagick.org/Usage/basics/#alpha
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/