About 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?".
Locked
disburden
Posts: 7
Joined: 2019-08-08T11:12:46-07:00
Authentication code: 1152

About rounded corners

Post by disburden »

Image
I have a picture, like A, only the shaded area has an image, the rest is transparent
Now I use the following command to round the corners of the image

Code: Select all

convert 111.png -alpha set -virtual-pixel transparent -channel A -blur 0x32  -threshold 50% +channel mm.png
or

Code: Select all

convert 111.png -virtual-pixel none -channel A -blur 0x32  -threshold 50% +channel  mm.png
I want a picture like B, only the top left corner is rounded.
But I now get a picture of C, which ignores the transparent area.
Ask for help. Thank you very much!

I uploaded a picture of my test
Image

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

Re: About rounded corners

Post by fmw42 »

This is one way to do that. Extract the alpha channel. Round all corners on a copy. Crop the upper left corner and put that back into the original alpha channel. Put the result back into the alpha channel of the image replacing the old alpha channel with the new processed one.

Unix syntax:

Code: Select all

convert image.png \
\( -clone 0 -alpha extract \) \
\( -clone 1 -virtual-pixel black -blur 0x32 -threshold 50% -crop 128x128+0+0 +repage \) \
\( -clone 1,2 -compose over -composite \) \
-delete 1,2 \
-alpha off -compose copy_opacity -composite \
result.png
If on Windows, remove the \ from the parentheses and change the end of line \ to ^

disburden
Posts: 7
Joined: 2019-08-08T11:12:46-07:00
Authentication code: 1152

Re: About rounded corners

Post by disburden »

@ fmw42,thank you for your reply,but there's a little bit of a problem, it seems that the rounded corners don't start in the right place
Image

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

Re: About rounded corners

Post by fmw42 »

Works fine for me on IM 6.9.10.97 Q16 Mac OSX

Input:
Image

Code: Select all

convert image.png \
\( -clone 0 -alpha extract \) \
\( -clone 1 -virtual-pixel black -blur 0x32 -threshold 50% -crop 128x128+0+0 +repage \) \
\( -clone 1,2 -compose over -composite \) \
-delete 1,2 \
-alpha off -compose copy_opacity -composite \
result.png
Image


What is your ImageMagick version and platform? If on Linux, what is the data of the ImageMagick version. What is your version of libpng?

Did you type my command correctly?


Try adding the +repage after reading the input and adding -gravity northwest near the end.

Code: Select all

convert image.png +repage\
\( -clone 0 -alpha extract \) \
\( -clone 1 -virtual-pixel black -blur 0x32 -threshold 50% -crop 128x128+0+0 +repage \) \
\( -clone 1,2 -compose over -composite \) \
-delete 1,2 \
-alpha off -gravity northwest -compose copy_opacity -composite \
result.png

disburden
Posts: 7
Joined: 2019-08-08T11:12:46-07:00
Authentication code: 1152

Re: About rounded corners

Post by disburden »

I think there may be some relationship with the Version, my current Version is ImageMagick 6.9.9-40 Q16,mac OSX too.
I'll upgrade to the latest version and try again

disburden
Posts: 7
Joined: 2019-08-08T11:12:46-07:00
Authentication code: 1152

Re: About rounded corners

Post by disburden »

Sorry, this seems to cause another problem, which is that the normal picture (no transparent area) also has only one rounded corner cut.

disburden
Posts: 7
Joined: 2019-08-08T11:12:46-07:00
Authentication code: 1152

Re: About rounded corners

Post by disburden »

Haha, I solved. Thank you very much!@ fmw42

Locked