Page 1 of 1

Rounded corners..

Posted: 2009-07-04T04:03:53-07:00
by cireFlow
Hi!

I'm trying to apply rounded corners to an image.. What I have so far is:

Code: Select all

convert -resize 800 xc:none -fill #111111 -draw "roundRectangle 0,0 800,534 1
5,15" bmx.jpg -compose SrcIn -composite bmx-result.jpg
The problems are:
-The image may have *any* aspect ratio. So I want the rounded rectangle's height to be equal to the image's height.
-I specified -fill #111111. But the background color remains black?!
-The corners do not seem to be antialiased. I tried adding the -antialias option right after convert, but it didn't change anything.

Thanks, cireFlow

Re: Rounded corners..

Posted: 2009-07-04T04:19:25-07:00
by Bonzo
There was a similar post to this earlier this week:
viewtopic.php?f=1&t=14135

Re: Rounded corners..

Posted: 2009-07-04T04:28:35-07:00
by cireFlow
Yeah, I also found the example you posted in the internet. But this is an image with known size.. I don't know the image's height.

Re: Rounded corners..

Posted: 2009-07-04T05:43:30-07:00
by Bonzo
If you look down the thread mentioned you will see some code from Anthony and a link; that is what you wanted.

This is a php version of his code and you should be able to modify it:

Code: Select all

<?php
$cmd = " $input ( +clone  -threshold -1 -draw \"fill black polygon 0,0 0,150 150,0 fill white circle 150,150 150,0\" ".
" ( +clone -flip ) -compose Multiply -composite ".
" ( +clone -flop ) -compose Multiply -composite ) +matte -compose CopyOpacity -composite";

exec("convert $cmd rounded_corners.png");
?>
<img src="rounded_corners.png" width="400">
This will also work but you need to change the angle corners to round ones:

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
Out of interest jpg does not support transparency thats why you have black corners.

Re: Rounded corners..

Posted: 2009-07-04T10:30:07-07:00
by cireFlow
OK, so using this command:

Code: Select all

convert bmx.jpg -resize 800 ( +clone -threshold -1 -draw "fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0" ( +clone -flop ) -compose Multiply -composite ) +matte -compose CopyOpacity -composite rounded_corners.png
I can resize the image and round the upper two corners (just what I want). But how can I do this for a whole directory? (I'm using Windows).

Code: Select all

for /f %%a IN ('dir /b *.jpg') do convert %%a -resize 800 ( +clone -threshold -1 -draw "fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0" ( +clone -flop ) -compose Multiply -composite ) +matte -compose CopyOpacity -composite %%a

This does not work, because the output file must have the png-extension.. It would also be OK if I could specify a background color instead of using transparency..

Re: Rounded corners..

Posted: 2009-07-05T10:56:34-07:00
by Bonzo
I had a play with batch files a month or so ago: http://www.rubblewebs.co.uk/imagemagick/batch.php but I was not really interested and only wrote some basic examples.

This worked for me on a whole directory ( this is the part you are looking for "%2\%%~nf.png" ):

Code: Select all

::Turn of displaying the code on the screen
@echo off

:: Read all the jpg images from the directory, resize them, add some text and save as a png in a different directory
for %%f in (%1\*.jpg) do ( convert %%f -resize 200x200 -pointsize 18 -fill black ^
-gravity northwest -annotate +0+0 "Some text" "%2\%%~nf.png" )
There is a Windows section on Anthony's example site now; http://www.imagemagick.org/Usage/windows/