Help me finish up this command?

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
xstatic
Posts: 13
Joined: 2014-11-13T00:48:47-07:00
Authentication code: 6789

Help me finish up this command?

Post by xstatic »

Hi! Having a hard time getting with a couple of issues here.

This command is creating shadowed text over a shadowed red rounded rectangle.

Code: Select all

/usr/bin/convert \( -background none -font Z003-Medium-Italic -pointsize 195 -fill black -gravity center label:"cat" \) \
 \( +clone -background black -shadow 80x5+5+5 \) -background none -layers merge +repage \ 
 \( -size 1328.89888x289.07865 xc:red -alpha set -virtual-pixel transparent -channel A -blur 0x15 -threshold 50% +channel \) \   
 +swap -compose over -composite \( +clone -background black -shadow 80x5+5+5 \) \ 
 -background black -layers merge +repage   /home/encodertraffic/subtitles/images/element-3.png

My main 2 issues are:

1. The rounded corners in this section are jaggy: -alpha set -virtual-pixel transparent -channel A -blur 0x15 -threshold 50% +channel

IS there anything I can do to have smoother edges?

2. Final command for the shadow behind the rectangle isn't working. It appears to be putting the shadow on top instead of behind.

Thank you for your help.

Craig

snibgo
Posts: 12904
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help me finish up this command?

Post by snibgo »

"-threshold 50%" will make every pixel either 0 or 100%, creating jaggies. If you don't want jaggies, remove the threshold, or replace it with something smoother like "-level 40,60%".

You have the rectangle, then the shadow, and you "-layers merge" them. You want the opposite order, so "+swap" before the merge.
snibgo's IM pages: im.snibgo.com

xstatic
Posts: 13
Joined: 2014-11-13T00:48:47-07:00
Authentication code: 6789

Re: Help me finish up this command?

Post by xstatic »

Thank you! If you don't mind a follow-up.

I am having a hard time understanding how to adjust the size of the curve/rounded edges using this method and just kind of having a hard time understanding how the rounded edges are being created in the first place. Is there kind of a formula to adjusting the blur and the level to get a consistent rounded corner?

Thanks so much for the help!!!

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

Re: Help me finish up this command?

Post by fmw42 »

I typically follow -blur 0xX with -level 50x100%.

snibgo
Posts: 12904
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help me finish up this command?

Post by snibgo »

xstatic wrote:Is there kind of a formula to adjusting the blur and the level to get a consistent rounded corner?
Not really. "-blur 0xX" will create a blur approximately 3*X wide, so about 1.5*X inside the edge and the same (invisible) outside the edge, so the radius of the corner is roughly 1.5*X, eg 1.5*15 = 22.5 pixels. The level, or other operation, can do various things.

You can play to see the different effects. I find white and black easier to see than opaque and transparent. For example:

magick -size 200x200 xc:White -virtual-pixel Black -blur 0x15 blcorn0.png
Image

magick -size 200x200 xc:White -virtual-pixel Black -blur 0x15 -threshold 50% blcorn1.png
Image

magick -size 200x200 xc:White -virtual-pixel Black -blur 0x15 -level 50,100% blcorn2.png
Image

magick -size 200x200 xc:White -virtual-pixel Black -blur 0x15 -level 40,60% blcorn3.png
Image
snibgo's IM pages: im.snibgo.com

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

Re: Help me finish up this command?

Post by fmw42 »

The level values control how much rolloff you have. If you have a big blur, you may not want 50x100% and may prefer 40x60% or some other value in-between. My blurs are usually not as big as 15. I typically blur by 0x1 or 0x2 after doing a threshold to smooth out the edges.

So if you are doing the blur only to round the corners, I would suggest you follow that with

Code: Select all

-threshold 50% -blur 0xX -level 50x100%  where X is about 1-3.

xstatic
Posts: 13
Joined: 2014-11-13T00:48:47-07:00
Authentication code: 6789

Re: Help me finish up this command?

Post by xstatic »

So, again, it almost seems like this method is for something else? I just want to be 100% sure this is the ideal way to go for smooth rounded corners of varying radius but consistent ratio. (without blur).

I am having a hard time getting the rounded part to be more rounded than just a little bit and I still can't quite get the science down on those settings. One minute I think I have it and then i make a slight change and everything gloes blurry.

My goal is to be do something equivalent to border-radius in HTML and change a number to increase the radius where you change a radius number and it keeps the border smooth, but just changes the radius evenly.

Image

Taking the commands above however, I am kind of all over the place. For instance using your 0x1 example I get:

-threshold 50% -blur 0x1 -level 50x100%

Image

That appears to have no rounding at all, so I increase the 0x1 to 0x3:

Image

This one also isn't really rounded on the corners and starting to get too blurry as I don't really want blurred edges, just anti-aliased ones.

So, then I tried this:

-threshold 50% -blur 0x3 -level 10x50%

and got which now, I have relatively smooth rounded corners, but they aren't extremely rounded.

Image

So, since upping the numbers seemed to work, I upped all of them again. Now I have a little more rounding, but the rounding ratio appears to be off this time. Is there a method to the madness or is it just a guessing game?
So, appreciate your time and help. :):) . I feel a bit dense here.

Image

snibgo
Posts: 12904
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help me finish up this command?

Post by snibgo »

xstatic wrote:My goal is to be do something equivalent to border-radius in HTML and change a number to increase the radius where you change a radius number ...
Although blurring a rectangle does round the corners, they are not arcs of circles. I suggest you "-draw roundRectangle" instead. That does the job more directly, with precise control of the width and height of the rounded corners to be removed. See https://www.imagemagick.org/script/comm ... s.php#draw
snibgo's IM pages: im.snibgo.com

xstatic
Posts: 13
Joined: 2014-11-13T00:48:47-07:00
Authentication code: 6789

Re: Help me finish up this command?

Post by xstatic »

Hey, thanks all for the help! I was able to get it all sorted out and understood and finish up my project. Thanks for taking the time to help.
:)

Post Reply