Round the angles of the images

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?".
loul1933
Posts: 9
Joined: 2020-01-19T14:50:43-07:00
Authentication code: 1152
Location: La Brede, Aquitaine, FRANCE

Round the angles of the images

Post by loul1933 »

Hello
I'm looking to round the corners of my images with ImageMagick, but I haven't found any examples
Is this possible?
Thank you very much in advance for the reply.

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

Re: Round the angles of the images

Post by fmw42 »

See https://imagemagick.org/Usage/thumbnails/#rounded

Also above that where it says:

Code: Select all

convert thumbnail.gif -alpha set -virtual-pixel transparent -channel A -blur 0x8  -threshold 50% +channel rounded_corner_blur.gif

loul1933
Posts: 9
Joined: 2020-01-19T14:50:43-07:00
Authentication code: 1152
Location: La Brede, Aquitaine, FRANCE

Re: Round the angles of the images

Post by loul1933 »

Thank you very much for this answer, I don't speak English well, but luckily Google Trad helps me.
I will test the different formats tomorrow
and I will make you a touch
thanks again

loul1933
Posts: 9
Joined: 2020-01-19T14:50:43-07:00
Authentication code: 1152
Location: La Brede, Aquitaine, FRANCE

Re: Round the angles of the images

Post by loul1933 »

I come back to you, I'm "newsbee", in the way of using the command line, but when I copy and paste in a terminal, example lines, it puts me a> at the beginning of the line and I do not do it (to change the name of the files of emission and reception of the script?
Anyway, I'm blocking: - ((

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

Re: Round the angles of the images

Post by fmw42 »

What is your ImageMagick version? What is your platform/OS -- are you on Windows or Linux or Mac?

The > is a command prompt in some systems. Just ignore that. Paste or type your command there and hit return.

loul1933
Posts: 9
Joined: 2020-01-19T14:50:43-07:00
Authentication code: 1152
Location: La Brede, Aquitaine, FRANCE

Re: Round the angles of the images

Post by loul1933 »

Sorry, i'm on Mageia 7.1 linux and my version of ImageMagick is 7.0.8.62
and
when I copy and paste the lines of the example in my terminal, I can only modify the last line (my original prompt is "$"). I tried removing the line returns "/", but it did not work, and I think this command is for images of type "thumbnails" not popur images of 800X600 jpg for example
Thank's

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

Re: Round the angles of the images

Post by fmw42 »

What was the command you tried? Was it

Code: Select all

magick thumbnail.gif \
\( +clone  -alpha extract \
-draw 'fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0' \
\( +clone -flip \) -compose Multiply -composite \
\( +clone -flop \) -compose Multiply -composite \
\) -alpha off -compose CopyOpacity -composite  rounded_corners.png

If so try the above where I have removed any leading tabs or spaces and any spaces after the line ending \

or was it

Code: Select all

magick thumbnail.gif -alpha set -virtual-pixel transparent -channel A -blur 0x8  -threshold 50% +channel rounded_corner_blur.gif
If the first command above, then try removing only the end of line \ as:

Code: Select all

convert thumbnail.gif \( +clone  -alpha extract -draw 'fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0' \( +clone -flip \) -compose Multiply -composite \( +clone -flop \) -compose Multiply -composite \) -alpha off -compose CopyOpacity -composite  rounded_corners.png
Replace your input and output files for the ones in the commands. It should work for any size image. But for larger images, you need to change all the 15 number to much larger values (say about 10% of the width and height of the image)

Similarly in the second command, increase the value where its shows 8 in the blur 0x8.

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

Re: Round the angles of the images

Post by fmw42 »

With IM 7, you can set the rounding amount to be some percent of the dimensions of the image. So say 10% = 0.1 as a fraction.

Code: Select all

magick input \
\( +clone  -alpha extract \
-draw 'fill black polygon 0,0 0,"%[fx:0.1*min(w,h)]" %[fx:0.1*min(w,h)],0 fill white circle %[fx:0.1*min(w,h)],%[fx:0.1*min(w,h)] %[fx:0.1*min(w,h)],0' \
\( +clone -flip \) -compose Multiply -composite \
\( +clone -flop \) -compose Multiply -composite \
\) -alpha off -compose CopyOpacity -composite  output

loul1933
Posts: 9
Joined: 2020-01-19T14:50:43-07:00
Authentication code: 1152
Location: La Brede, Aquitaine, FRANCE

Re: Round the angles of the images

Post by loul1933 »

Good evening,
Thank you very much for taking care of me
The last example in percentage worked perfectly and on different image sizes.
I think I can use it on images both in width and in height!
and I also think that I can insert it into a Mogrify
If you have a little time, can you explain to me why there are "+ clone" in the command
can you explain to me the black polygon and the white circle, please !! I get a bit lost with these functions
In any case still BIG THANKS
best regards
JL B

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

Re: Round the angles of the images

Post by fmw42 »

The code is processing one quadrant of the image at a time by drawing a black polygon in the upper left corner and then a white quarter circle as a mask and then applying it to the image. The white part keeps the image and black part will make it transparent there. The clones make copies of the mask and flip the mask so that it corresponds to each corner.

loul1933
Posts: 9
Joined: 2020-01-19T14:50:43-07:00
Authentication code: 1152
Location: La Brede, Aquitaine, FRANCE

Re: Round the angles of the images

Post by loul1933 »

again a big thank you for these explanations :D

loul1933
Posts: 9
Joined: 2020-01-19T14:50:43-07:00
Authentication code: 1152
Location: La Brede, Aquitaine, FRANCE

Re: Round the angles of the images

Post by loul1933 »

Good evening, I come back to you, I have another problem.
I installed the command you sent me in a "for" loop to process all the jpg files in the directory

for f in * .jpg; do magick $ f.jpg \
\ (+ clone -alpha extract \
-draw 'fill black polygon 0.0 0, "% [fx: 0.05 * min (w, h)]"% [fx: 0.05 * min (w, h)], 0 fill white circle% [fx: 0.05 * min (w, h)],% [fx: 0.05 * min (w, h)]% [fx: 0.05 * min (w, h)], 0 '\
\ (+ clone -flip \) -compose Multiply -composite \
\ (+ clone -flop \) -compose Multiply-composite \
\) -alpha off -compose CopyOpacity -composite $ f.png; therefore

but he answers me this:
"bash: syntax error near unexpected symbol" done "

the command only works by naming a file !!!
I hold
Thanks if you can help me

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

Re: Round the angles of the images

Post by fmw42 »

There is no "therefore" at the end of a loop. It should be "done". Also, It seems you have badly mistyped my command.

There should be no space between $ and f. There should be a space between quotes and % and no space between % and [. You also have a period in place of a comma and other issues.


See below

Try:

Code: Select all

for f in *.jpg; do 
magick $f.jpg \
\( +clone -alpha extract \
-draw 'fill black polygon 0,0 0,"%[fx:0.1*min(w,h)]" %[fx:0.1*min(w,h)],0 \
fill white circle %[fx:0.1*min(w,h)],%[fx:0.1*min(w,h)] %[fx:0.1*min(w,h)],0' \
\( +clone -flip \) -compose Multiply -composite \
\( +clone -flop \) -compose Multiply -composite \
\) -alpha off -compose CopyOpacity -composite $f.png
done

loul1933
Posts: 9
Joined: 2020-01-19T14:50:43-07:00
Authentication code: 1152
Location: La Brede, Aquitaine, FRANCE

Re: Round the angles of the images

Post by loul1933 »

Hello,
Thank you for the feedback,
I do not understand why there was this 'therefore', I had put done to finish ??
I tested your script, but it reports syntax errors.
I put my prompt in color to make it more readable
Weird that at the first clone he answered me:
bash: syntax error near unexpected symbol "("
and that in the second, it is something else:
bash: syntax error near the unexpected symbol "+"

here is the essay:

Code: Select all

papi71@localhost:images\:$ 
papi71@localhost:images\:$ for f in * .jpg; do 
> magick $f.jpg \
> \ (+ clone -alpha extract \
bash: erreur de syntaxe près du symbole inattendu « ( »
papi71@localhost:images\:$ -draw 'fill black polygon 0,0 0,"%[fx:0.1*min(w,h)]" %[fx:0.1*min(w,h)],0 \
> fill white circle %[fx:0.1*min(w,h)],%[fx:0.1*min(w,h)] %[fx:0.1*min(w,h)],0' \
> \ (+ clone -flip \) -compose Multiply -composite \
bash: erreur de syntaxe près du symbole inattendu « ( »
papi71@localhost:images\:$ \ (+ clone -flop \) -compose Multiply-composite \
bash: erreur de syntaxe près du symbole inattendu « + »
papi71@localhost:images\:$ \) -alpha off -compose CopyOpacity -composite $f.png
bash: ) : commande introuvable
papi71@localhost:images\:$ done
bash: erreur de syntaxe près du symbole inattendu « done »
papi71@localhost:images\:$
thank you again very much for your help, I have not often worked on the command line, and I am .... 71 years old :D :D , which does not prevent me from wanting to work these images

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

Re: Round the angles of the images

Post by fmw42 »

You have spaces between + and clone. You have no space between ( and +, which is needed. You have copied my code badly again. There are many other mistakes. You also cannot do $f.png for your output. It objects when I do it. You need to get the name without the suffix. Try the following. It works fine for me.

Code: Select all

for f in *.jpg; do
magick $f -set filename:nm "%t" \
\( +clone -alpha extract \
-draw 'fill black polygon 0,0 0,"%[fx:0.1*min(w,h)]" %[fx:0.1*min(w,h)],0 \
fill white circle %[fx:0.1*min(w,h)],%[fx:0.1*min(w,h)] %[fx:0.1*min(w,h)],0' \
\( +clone -flip \) -compose Multiply -composite \
\( +clone -flop \) -compose Multiply -composite \
\) -alpha off -compose CopyOpacity -composite %[filename:nm].png
done
Be careful that you put spaces where they are needed such as around parentheses and before -. Also remove spaces between $ and whatever follows and between * and whatever follows and - and whatever follows.

Post Reply