Transparent, rounded corners

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".

Transparent, rounded corners

Postby makrell66 » 2007-02-06T01:04:05+00:00

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 -
makrell66
 
Posts: 4
Joined: 2007-02-06T00:55:36+00:00

Re: Transparent, rounded corners

Postby Bonzo » 2007-02-06T11:46:34+00:00

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");
Bonzo
 
Posts: 1155
Joined: 2006-05-20T08:08:19+00:00
Location: Cambridge, England

Re: Transparent, rounded corners

Postby makrell66 » 2007-02-07T05:33:51+00:00

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 -
makrell66
 
Posts: 4
Joined: 2007-02-06T00:55:36+00:00

Re: Transparent, rounded corners

Postby Bonzo » 2007-02-07T11:14:22+00:00

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.
ImageMagick examples mostly using php http://www.rubblewebs.co.uk/imagemagick/
New section ( still in progress ) showing examples of all the operators http://www.rubblewebs.co.uk/imagemagick/operator.php
Bonzo
 
Posts: 1155
Joined: 2006-05-20T08:08:19+00:00
Location: Cambridge, England

Re: Transparent, rounded corners

Postby magick » 2007-02-07T11:19:34+00:00

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.
User avatar
magick
Site Admin
 
Posts: 6518
Joined: 2003-05-31T11:32:55+00:00

Re: Transparent, rounded corners

Postby Bonzo » 2007-02-07T11:57:39+00:00

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 Very Happy

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");
ImageMagick examples mostly using php http://www.rubblewebs.co.uk/imagemagick/
New section ( still in progress ) showing examples of all the operators http://www.rubblewebs.co.uk/imagemagick/operator.php
Bonzo
 
Posts: 1155
Joined: 2006-05-20T08:08:19+00:00
Location: Cambridge, England

Re: Transparent, rounded corners

Postby el_supremo » 2007-02-07T13:28:51+00:00

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
el_supremo
 
Posts: 746
Joined: 2005-03-21T21:16:57+00:00

Re: Transparent, rounded corners

Postby anthony » 2007-02-07T21:37:38+00:00

All interesting.. here is my 2 cents

IM Examples Thumbanils
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 4377
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: Transparent, rounded corners

Postby bram12 » 2008-10-14T02:45:33+00:00

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??
bram12
 
Posts: 15
Joined: 2008-10-14T02:40:20+00:00

Re: Transparent, rounded corners

Postby Bonzo » 2008-10-14T05:04:05+00:00

Looking at the details of the image created it is a jpg file and jpg dos not support transparency.
ImageMagick examples mostly using php http://www.rubblewebs.co.uk/imagemagick/
New section ( still in progress ) showing examples of all the operators http://www.rubblewebs.co.uk/imagemagick/operator.php
Bonzo
 
Posts: 1155
Joined: 2006-05-20T08:08:19+00:00
Location: Cambridge, England

Re: Transparent, rounded corners

Postby bram12 » 2008-10-14T07:04:48+00:00

pffff... yes sorry you are correct.
bram12
 
Posts: 15
Joined: 2008-10-14T02:40:20+00:00


Return to Users

Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 5 guests