Creating a rounded corner

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?".
Post Reply
riegel
Posts: 26
Joined: 2003-08-19T12:36:46-07:00
Location: Rocky Mount, NC 27804

Creating a rounded corner

Post by riegel »

Hello,

I modified the code from http://www.cit.gu.edu.au/~anthony/graph ... humbnails/ for creating rounded corners so that it could be used all in one command.

On the site I changed this...

Code: Select all

convert -size 15x15 xc:white -draw 'circle 0,0 0,14' \
            \( xc:none -draw 'circle 0,0 0,12' \) \
            -compose DstOut -composite     rounded_corner.png


    convert thumbnail.gif   -bordercolor black -border 2 -matte \
            \( rounded_corner.png -flip -flop \) -gravity NorthWest -composite \
            \( rounded_corner.png       -flop \) -gravity SouthWest -composite \
            \( rounded_corner.png -flip       \) -gravity NorthEast -composite \
            \( rounded_corner.png             \) -gravity SouthEast -composite \
            +matte  -depth 8  -quality 95  rounded_corners.png

It now looks like this...

Code: Select all

[SRC]
-geometry 200x200
-bordercolor "#9FB08E"
-border 2
\( -size 15x15
   xc:white
   -draw 'circle 0,0 0,14'
   \( xc:none
      -draw
      'circle 0,0 0,12' \)
   -compose DstOut
   -composite
   -flip -flop \)
-gravity NorthWest
-composite
My problem is since I do not fully understand the code I can't seem to figure out how to change the color of the rounded border. Any ideas on how I can do this.

Image

I would like to make the border and corner green.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

before the first -draw add -fill "#9FB08E"
The default fill color is black. The color of the second draw does not matter as it is a mask which only looks at the transparency components of that image.

Also once you have made one corner image, save it into an mpr: in memory image register, and delete the image from the current image sequence. That way you can just copy the image from the mpr: without having re-create it over and over, or use a temporary file on the disk.

Code: Select all

convert -size 15x15 xc:white -fill #9FB08E"  -draw 'circle 0,0 0,14' \
            \( xc:none -draw 'circle 0,0 0,12' \) \
            -compose DstOut -composite  -write mpr:corner +delete \
           IMAGE.PNG  -bordercolor  #9FB08E"-border 2 -matte \
          \( mpr:corner -flip -flop \) -gravity NorthWest -composite \
          .... \
          rounded_corners.png
Just repeat the ... part as in my examples to overlay the corner image on each of the four corners.

If you want the corners masked to transparency instead of white (set using the first xc:), you will need two images, one overlay, to color the corner, and another to make the transparent parts, transparent. I believe it ws the next example in IM Examples.

Note the circle radius of 12 and 14, is two pixels different to match up to the 2 pixel border. Adjust as you see fit.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply