Flatten or merge removes image. Help!!

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?".
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Flatten or merge removes image. Help!!

Post by anthony »

About the code...

Code: Select all

-stroke black ... -channel A -blur 0x2 +channel -auto-level +level-colors "#24acff,white" 
You draw a black line on transparency. No problem. But then you blur the line but blur the line ONLY USING ALPHA. That means while the line is blurred, The color channels are not. As such any nearby transparency now becomes semi-transparent. However transparent color is technically undefined! As such you now have a blurred line surrounded by a undefined semi-transparent color, which you then modify!
See the effects of this in...
http://www.imagemagick.org/Usage/blur/#blur_internals

Now it so happens I know the transparency color is black. So the result would be a blurred black line. But you should NOT be relying on that fact! Finally you use -auto-level (everything is black so that does nothing), and the use +level-color to color that black though the operation is really for a black to white gradient of colors. You get the wanted result, but only by accident!

Basically it is just not thought out, step-by-step. Here is the right solution!

Code: Select all

  \( -clone 0 -stroke "#24acff" -fill none -strokewidth 3 -draw "arc 10,10 130,130 80,102" \
         -channel RGBA -blur 0x2 -channel A -auto-level +channel -write arc2.png \) \
Note that the auto-level is now restricted to just alpha channel. You don't want to change the color, just the transparency levels.

Note that I specifically turn off 'fill color'. That was the cause of your original problem.
See IM Examples, Draw Primitives, Arc
http://www.imagemagick.org/Usage/draw/#primitive_arc
Note the areas that were given a white color! That is the area given a fill color.

NOTE you can specify fill stroke and stroke-width settings (using the appropriate MVG equivalents) inside the draw string. This will limit those settings to just that draw string only.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Flatten or merge removes image. Help!!

Post by anthony »

Going back to your original problem, using the images you gave.. Try this...

Code: Select all

convert -size 150x150 xc:none \
      \( -clone 0 -fill none -stroke gray80 -strokewidth 1 \
         -draw "arc 10,10 130,130 120,280" \
         \( +clone -background black  -shadow 100x2+0+0 \
            -crop 150x150+0+0 \) +swap -composite \) \
      \( -clone 0 -fill none -stroke white -strokewidth 3 \
         -draw "stroke-linecap round  arc 10,10 130,130 80,120" \
         \( +clone -background dodgerblue -shadow 100x4+0+0 \
            -crop 150x150+0+0 \) +swap -composite \) \
      -delete 0 -composite audio_meter.png
Image
All you need now is to calculate the positions for the small circles at the ends of the small 'arc'.
But in the mean time I made it a but thicker and added round end caps.

One of those circles is fixed, but both may be at a floating point position. Do not be afraid of the floating point positions, as draw accepts and handles floating point values just fine!

Do this before the sub-parenthesis so that the 'shadow' glow effect is calculated AFTER the circles have been added.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
palobo
Posts: 10
Joined: 2011-05-23T04:22:06-07:00
Authentication code: 8675308

Re: Flatten or merge removes image. Help!!

Post by palobo »

Anthony,

I took your last suggestion and finally got the result I desired!
Image

Your solution is elegant and your IM knowledge humbling.

My thanks to both you and Fred. From what I've seen around the forum both your names come up recurringly and almost always with solutions.

Thank you both.

For anybody else trolling archives later on, this is the code I came up with (hehe... "came up with" almost sounds like I got there on my own.. :) ):

Code: Select all

convert -size 150x150 xc:none   \
     \( -clone 0 -fill none -stroke grey90 -strokewidth 1    -draw "arc 10,10 130,130 120,280"  \
     \( +clone -background black  -shadow 100x3+0+0  -crop 150x150+0+0 \) +swap -composite \) \
     \( -clone 0 -fill none -stroke white -strokewidth 2  \
            -draw "stroke-linecap round  arc 10,10 130,130 80,120" -strokewidth 5 -stroke white \ 
            -draw "stroke-linecap round arc 10,10 130,130 80,80.0001" -strokewidth 5 -stroke white \
            -draw "stroke-linecap round arc 10,10 130,130 120,120.0001"  \
            \( +clone -background dodgerblue -shadow 100x4+0+0   -crop 150x150+0+0 \) +swap -composite \)  \
     -delete 0 -composite audio_meter.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Flatten or merge removes image. Help!!

Post by anthony »

I see you came up with the use of generating circles using the 'endcap' method I had listed in IM examples. I'd forgotton about that. Niffy as it means you did not need to calculate the circle positions, but let IM do it.

The only modification I would make would be to merge those circle drawing into a single draw command, (all in a single set of quotes to make it a single draw argument) but this is only a minor change.

Code: Select all

      \( -clone 0 -fill none -stroke white -strokewidth 2 \
         -draw "arc 10,10 130,130 80,120 \
                stroke-linecap round  stroke-width 6 \
                arc 10,10 130,130  80,80.001 \
                arc 10,10 130,130 120,120.001" \
         \( +clone -background dodgerblue -shadow 100x4+0+0 \
            -crop 150x150+0+0 \) +swap -composite \) \
PS: watch your indents. They can be important when reading and following the steps when parenthesis is involved. It is basically good coding practice.

ASIDE: for those trying to follow the above. the only reason the crop is used in the above is because -shadow generates a slightly bigger image to ensure its results fits into the image. That extra space is not needed in this situation. I probably should include a +repage after the crop.

Also note that I have not 'darkened' the outline results of the shadow as shown in.
http://www.imagemagick.org/Usage/blur/#shadow_outline
But that does not seem to be needed in this case.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply