draw ROUND images on a background, is it possible?

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
silversonicaxel
Posts: 10
Joined: 2013-12-19T07:00:20-07:00
Authentication code: 6789

draw ROUND images on a background, is it possible?

Post by silversonicaxel »

Hi guys,
I need to put some images on a background, and that's working fine with the following code:

Code: Select all

convert -size 600x357 xc:none -draw "image Over 0,0 0,0 'background01.jpg'" -draw "image Over 25,190 0,0 'aktiviteiten01.jpg'" -draw "image Over 200,190 0,0 'cultuur13.jpg'" -draw "image Over 380,190 0,0 'natuur01.jpg'" -draw "image Over 0,0 0,0 'frame.png'" -extent 600x357 -append +repage 638044758.30105944.jpg

I've even some images that need to be put over my background, just circular shaped. Following the rules of -draw command here (http://www.imagemagick.org/script/comma ... s.php#draw) it appears my code needs to change like the following:

Code: Select all

convert -size 600x357 xc:none -draw "image Over 0,0 0,0 'background01.jpg'" -draw "image Over 25,190 0,0 'aktiviteiten01.jpg'" -draw "circle 200,190 0,0 'cultuur13.jpg'" -draw "image Over 380,190 0,0 'natuur01.jpg'" -draw "image Over 0,0 0,0 'frame.png'" -extent 600x357 -append +repage 638044758.30105944.jpg
but I receive this error:

Code: Select all

convert.exe: Non-conforming drawing primitive definition `cultuur13.jpg' @ error/draw.c/DrawImage/3178.
does anybody knows why? thanks in advance
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: draw ROUND images on a background, is it possible?

Post by snibgo »

"draw circle" doesn't take a filename as an argument. "draw image" is the only one that does. See http://www.imagemagick.org/script/comma ... s.php#draw

"draw circle" will use a fill colour or tile from an image, so that is one way of doing it. Eg:

Code: Select all

convert logo: -write l0.png +level 30,70%% l1.png

convert l0.png -tile l1.png -draw "circle 100,100 100,200" l3.png
snibgo's IM pages: im.snibgo.com
silversonicaxel
Posts: 10
Joined: 2013-12-19T07:00:20-07:00
Authentication code: 6789

Re: draw ROUND images on a background, is it possible?

Post by silversonicaxel »

Question, this is circle options:

Code: Select all

circle x0,y0 x1,y1

but if i write

Code: Select all

"circle 0,0 300,150"
or

Code: Select all

"circle 0,0 150,300"
nothing changes.
its behavior is not so clear.

what do x0,y0 x1,y1 stand for then?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: draw ROUND images on a background, is it possible?

Post by Bonzo »

what do x0,y0 x1,y1 stand for then?
x0,y0 = centre of the circle

x1,y1 = a point on the cricumference of the circle

See: http://www.imagemagick.org/script/comma ... s.php#draw
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: draw ROUND images on a background, is it possible?

Post by fmw42 »

You may be better off compositing with a circular mask using -compose ... -composite. Use -draw to create a white circle on a black or transparent background and use that as mask image to cut out a circle of one image and overlay it on another.

see
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/Usage/thumbnails/#rounded


Here is an example

Image Image


#line1 - read the background and foreground images
#line2 - clone the foreground image and make it all black, then draw a white circle centered and to the edges
#line3 - copy the foreground image and the circle image and put the circle into the alpha channel of the foreground image
#line4 - delete the original foreground image and circle mask and composite the modified foreground over the center of the background

convert tile_water2.jpg zelda3.jpg \
\( -clone 1 -fill black -colorize 100 -fill white -draw "circle 64,64 64,0" \) \
\( -clone 1 -clone 2 -alpha off -compose copy_opacity -composite \) \
-delete 1,2 -gravity center -compose over -composite zelda3_circle.jpg

Image


see
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/script/comma ... p#colorize
http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/compose/#copyopacity
http://www.imagemagick.org/Usage/draw/#circles

If using windows, the \( ... \) should be ( ... ) and the line continuation \ should be ^

see
http://www.imagemagick.org/Usage/windows/
silversonicaxel
Posts: 10
Joined: 2013-12-19T07:00:20-07:00
Authentication code: 6789

Re: draw ROUND images on a background, is it possible?

Post by silversonicaxel »

Hi, everything is clear now, and it works perfectly.
Only one thing, what if I would like to position somewhere the circle?
maybe not centered but on a side, how can I set the X and Y of the circle?

thanks a lot
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: draw ROUND images on a background, is it possible?

Post by fmw42 »

change

Code: Select all

-delete 1,2 -gravity center -compose over -composite zelda3_circle.jpg
to

Code: Select all

-delete 1,2 -gravity center -geometry +X+Y -compose over -composite zelda3_circle.jpg
for which X,Y are relative to the center of the background image.

Or if you want it at the sides, you can change the -gravity to its other compass directions, such as east, west, north, south, northeast, northwest, etc
Post Reply