Page 1 of 1

Transparent, rounded corners

Posted: 2007-02-06T01:04:05-07:00
by makrell66
I've been looking around, but I'm not able to find out how to create transparent, rounded corners.
The tricky bit is the transparency. I manage to create rounded corners with a colored background, but can not find out how to proceed to make them transparent.

- m66 -

Re: Transparent, rounded corners

Posted: 2007-02-06T11:46:34-07:00
by Bonzo
To make the colour in an image transparent you can do this.

Code: Select all

exec("/usr/local/bin/convert start_image.jpg -transparent red output_image.gif");

Re: Transparent, rounded corners

Posted: 2007-02-07T05:33:51-07:00
by makrell66
Thanks, that helped me a lot.

One other thing; all examples I have seen to create rounded corners, four individual corner images are created, and then composed on to the original image.

Will it be possible to create one mask (a rectangular image) with all four corners (colored), and use this to compose on to the original image?

- m66 -

Re: Transparent, rounded corners

Posted: 2007-02-07T11:14:22-07:00
by Bonzo
You could do that; I tried it out before and the result is at the bottom of this page: http://www.rubblewebs.co.uk/imagemagick/other.php

Code: Select all

exec("/usr/local/bin/convert snow.jpg -composite masktemp2.png -composite temp2.png");
exec("/usr/local/bin/convert temp2.png -transparent PeachPuff round_snow2.gif");
unlink( 'temp2.png' );
It worked but you have to make sure all the original photo gets covered by the mask and the colour you are using to make transparent is not in the original photo you want to keep.

This discussion came up before and you can use "DstOut" but I can not find the method I used for this. If I do I will post the code.

Re: Transparent, rounded corners

Posted: 2007-02-07T11:19:34-07:00
by magick
Try -vignette. Is that similar to what you want? If so you need to draw a mask (vignette draws an ellipse) and use -flatten to combine the layers.

Re: Transparent, rounded corners

Posted: 2007-02-07T11:57:39-07:00
by Bonzo
This is some code for DstIn and DstOut; the transparency is showing up black - I got over this before but can not remember how I did it.
Hopefuly Anthony will read this post and put me straight :D

http://www.rubblewebs.co.uk/imagemagick ... rell66.php

Code: Select all

exec("/usr/local/bin/convert -size 358x358 xc:none -fill black -draw \"circle 177,177 177,10\" mask.png");
exec("/usr/local/bin/convert earth.jpg -gravity center -compose DstOut mask.png -composite result_dst_out.png");
exec("/usr/local/bin/convert earth.jpg -gravity center -compose  DstIn mask.png -composite result_dst_in.png");

Re: Transparent, rounded corners

Posted: 2007-02-07T13:28:51-07:00
by el_supremo
Try this to see if it's the sort of thing you want:

Code: Select all

convert -size 640x480 xc:none -fill white -draw 'roundRectangle 15,15 624,464 15,15' logo: -compose SrcIn -composite logo_rounded_frame.png
Pete

Re: Transparent, rounded corners

Posted: 2007-02-07T21:37:38-07:00
by anthony
All interesting.. here is my 2 cents

IM Examples, Thumbnails, Adding Fluff
http://www.imagemagick.org/Usage/thumbn ... ded_border
Also look at the example above it using a unusual 'virtual-pixel' bluring technique.

I did have a corner example like what you describe, but it was removed as it was really more of a repeat of the method used in 'fancy' borders further down. I plan to return it to IM examples but in another form.

kepp the examples comming. preferably with actual results, or using built-in images as the test image.

Re: Transparent, rounded corners

Posted: 2008-10-14T02:45:33-07:00
by bram12
hi anthony

I tried your example on http://www.freeonlinephotoeditor.com (as many examples :) )
But the round corner does not seem to work, see the site and then 'effects' and then 'round corners'. The background is not tranparant.

PHP code:

Code: Select all

$size_img= getimagesize($filenameclean);
$width=$size_img[0]+2;
$height=$size_img[1]+2;
exec('convert '.extractname($_REQUEST["imageFileName"]).' -border 2 -matte -channel RGBA -threshold -1 -background none -fill none -stroke black -strokewidth 3 -draw \'roundrectangle 1,1 '.$width.','.$height.' 15,15\' '.$imagesurse_corner_overlay.'');
exec('convert '.extractname($_REQUEST["imageFileName"]).' -border 2 -matte -channel RGBA -threshold -1 -background none -fill white -stroke black -strokewidth 1 -draw \'roundrectangle 1,1 '.$width.','.$height.' 15,15\' '.$imagesurse_corner_mask.'');
exec('convert '.extractname($_REQUEST["imageFileName"]).' -matte -bordercolor none -border 2  '.$imagesurse_corner_mask.' -compose DstIn -composite '.$imagesurse_corner_overlay.' -compose Over -composite '.$imagesurse.'');
Any idea??

Re: Transparent, rounded corners

Posted: 2008-10-14T05:04:05-07:00
by Bonzo
Looking at the details of the image created it is a jpg file and jpg dos not support transparency.

Re: Transparent, rounded corners

Posted: 2008-10-14T07:04:48-07:00
by bram12
pffff... yes sorry you are correct.

Re: Transparent, rounded corners

Posted: 2011-09-02T01:09:40-07:00
by Jorge
i found the link with the code provided in here unverse.net/css-rounded, just if anyone needs it by now. :)

Re: Transparent, rounded corners

Posted: 2011-09-02T03:52:21-07:00
by anthony
I would say reselecting a thread from 3 years ago is generally not a good idea.

The pointed out artical is a basic technique, but more about generating images for web page markup, than adding rounded corners to actual images which is the topic of this (old) discussion.

The only thing I would have to say is...
  1. when drawing the circle, draw it on a even numbers sized image
  2. with even numbered images the center of the circle is drawn at a 0.5 offset. EG: (size-1)/2 as draw uses pixel coordinates
  3. now divide the image by using equal area crop
    http://www.imagemagick.org/Usage/crop/#crop_equal