Page 1 of 2
Flatten or merge removes image. Help!!
Posted: 2011-05-23T07:45:52-07:00
by palobo
Hey all.
I'm coming along further with my IM experiments.
One thing bugging me though. I've followed a few examples and have managed to create the effect I desired. The only downside so far is that when I flatten the layers I lose tranaparent background.
My code so far is this:
Code: Select all
convert -size 150x150 \( xc:none -fill none -stroke black -strokewidth 1 -draw "arc 10,10 130,130 102,280" -channel RGBA -blur 0x4 \) \( xc:none -stroke white -strokewidth 1 -draw "arc 10,10 130,130 102,280" -channel a -evaluate divide 3 \) \( xc:none -stroke black -strokewidth 3 -draw "arc 10,10 130,130 80,102" -channel A -blur 0x2 \( +clone xc:none -fill "#24acff" -draw 'color 0,0 reset' \) -compose ATop -composite \) -layers merge arc.png
If I add a -background none at the end I just end up with transparent square without anything else.
What am I doing wrong here???
Cheers,
PL
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T09:51:04-07:00
by fmw42
try
convert -respect-parenthesis -size 150x150 xc:none \
\( -clone 0 -fill none -stroke black -strokewidth 1 -draw "arc 10,10 130,130 102,280" -channel RGBA -blur 0x4 \) \
\( -clone 0 -stroke white -strokewidth 1 -draw "arc 10,10 130,130 102,280" -channel a -evaluate divide 3 \) \
\( -clone 0 -stroke black -strokewidth 3 -draw "arc 10,10 130,130 80,102" -channel A -blur 0x2 \
\( +clone -clone 0 -fill "#24acff" -draw 'color 0,0 reset' \) -compose ATop -composite \) \
-background none -layers merge arc.png
Is this what you want for the result?
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T10:05:26-07:00
by palobo
Hi,
Thanks for your quick reply.
I'm trying to recreate this
using IM. Your code renders this result on my current machine (Will test on another later tonight)
I've managed to get a decent result, very close to the original but only with a white background
Any further ideas?
Cheers and TIA
PL
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T10:07:25-07:00
by palobo
Let me take this oportunity to say thanks for showing me a better way of creating the various layers
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T10:45:59-07:00
by fmw42
why don't you put write statements in each paren to see what is being generated and if correct. I really don't understand each step. So that may help you figure out what you are doing wrong. or perhaps explain step by step what you are trying to do functionally -- what is the goal off each step?
convert -respect-parenthesis -size 150x150 xc:none \
\( -clone 0 -fill none -stroke black -strokewidth 1 -draw "arc 10,10 130,130 102,280" -channel RGBA -blur 0x4 -write arc1.png \) \
\( -clone 0 -stroke white -strokewidth 1 -draw "arc 10,10 130,130 102,280" -channel a -evaluate divide 3 +channel -write arc2.png \) \
\( -clone 0 -stroke black -strokewidth 3 -draw "arc 10,10 130,130 80,102" -channel A -blur 0x2 +channel -write arc3.png \
\( +clone -clone 0 -fill "#24acff" -draw 'color 0,0 reset' \) -compose ATop -composite -write arc4.png \) \
-background none -layers merge arc.png
Try this and see if closer:
convert -respect-parenthesis -size 150x150 xc:none \
\( -clone 0 -fill none -stroke white -strokewidth 3 -draw "arc 10,10 130,130 102,280" -edge 1 -negate -write arc1.png \) \
\( -clone 0 -fill none -stroke black -strokewidth 3 -draw "arc 10,10 130,130 80,102" -blur 0x2 -auto-level +level-colors "#24acff,white" -write arc2.png \) \
-background none -flatten arc1a.png
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T11:18:36-07:00
by palobo
Hi,
Thanks again for your guidance.
As per your suggestion, here it is again with result from write and step by step guide.
Code: Select all
convert -respect-parenthesis -size 150x150 xc:none \
\( -clone 0 -fill none -stroke black -strokewidth 1 -draw "arc 10,10 130,130 102,280" -channel RGBA -blur 0x4 -write arc1.png \) \
\( -clone 0 -fill none -stroke white -strokewidth 1 -draw "arc 10,10 130,130 102,280" -channel a -evaluate divide 3 +channel -write arc2.png \) \
\( -clone 0 -fill none -stroke black -strokewidth 3 -draw "arc 10,10 130,130 80,102" -channel A -blur 0x2 \( +clone -clone 0 -fill "#24acff" -stroke none -draw 'color 0,0 reset' \) -compose ATop -composite -write arc3.png \) \
-background none -layers merge arc.png
Arc1.png:
Arc2.png:
arc3.png:
arc.png (with -layers merge only):
arc.png (with -background none -layers merge)
Step 1 is intended to create an outer glow/shadow without offset
Step 2 creates thin white line over the previous with some transparency
Step 3 is intended to create a blured stroke with color. It's done that way because of a bug (
http://www.imagemagick.org/Usage/bugs/blur_trans/)
What is intended is the first arc.png but with transparent background. From what I can see, everything is being created correctly, it's just the merge that is getting somehow messed up.
Cheers,
PL
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T12:15:13-07:00
by Bonzo
I think you are over complicating your comand with all the clones - why do you need the clones anyway? As you are creating the tempory images why not do it in more lines - you can always try combining them later.
php code that works:
Code: Select all
<?php
exec (" convert -size 150x150 xc:none -fill none -stroke black -strokewidth 1 -draw \"arc 10,10 130,130 102,280\" -channel RGBA -blur 0x4 arc1.png ");
exec (" convert -size 150x150 xc:none -fill none -stroke white -strokewidth 1 -draw \"arc 10,10 130,130 102,280\" -channel A -evaluate divide 3 +channel arc2.png ");
exec (" convert -size 150x150 xc:none -fill none -stroke black -strokewidth 3 -draw \"arc 10,10 130,130 80,102\" -channel A -blur 0x2 \( -clone 0 -fill \"#24acff\" -stroke none -draw \"color 0,0 reset\" \) -compose ATop -composite arc3.png ");
// The final image
exec ("convert -size 150x150 xc:none arc1.png -composite arc2.png -composite arc3.png -composite arc.png ");
// Putting the final image over a red background to prove it is transparent
exec ("convert -size 150x150 xc:red arc.png -composite background.png");
?>
<img src="arc1.png">
<img src="arc2.png">
<img src="arc3.png">
<img src="arc.png">
<img src="background.png">
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T12:39:58-07:00
by palobo
I've tried compositing the images, but I'm trying to do it all in one go. This is to be dynamically scripted with a high refresh rate so I need to avoid creating excessive temp files. The write arc1.png arc2.png are just to see what is being created along the way.
But if all else fails then yeah, I'll have to go that way.
Thanks though for your input.
Cheers,
PL
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T12:48:38-07:00
by Bonzo
This is a lot simpler comand but the blue is gray; but should be easier for others to understand:
Code: Select all
$cmd = " -size 150x150 xc:none \( -size 150x150 xc:none -fill none -stroke black -strokewidth 1 -draw \"arc 10,10 130,130 102,280\" -channel RGBA -blur 0x4 \) -composite ".
" \( -size 150x150 xc:none -fill none -stroke white -strokewidth 1 -draw \"arc 10,10 130,130 102,280\" -channel A -evaluate divide 3 +channel \) -composite ".
" \( -size 150x150 xc:none -fill none -stroke black -strokewidth 3 -draw \"arc 10,10 130,130 80,102\" -channel A -blur 0x2 \( -clone 0 -fill \"#24acff\" -stroke none -draw \"color 0,0 reset\" \) \) -composite ";
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T13:02:00-07:00
by fmw42
try this
convert -respect-parenthesis -size 150x150 xc:none \
\( -clone 0 -fill none -stroke black -strokewidth 1 -draw "arc 10,10 130,130 102,280" -channel RGBA -blur 0x4 -write arc1.png \) \
\( -clone 0 -stroke black -strokewidth 3 -draw "arc 10,10 130,130 80,102" -channel A -blur 0x2 +channel -auto-level +level-colors "#24acff,white" -write arc2.png \) \
-background none -flatten arc.png
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T13:31:58-07:00
by palobo
Awesome mate!!! That did the trick!
Could I be so bold as to ask for an explanation of what was going wrong and what exactly the fix does.
Cheers and thanks so much for your help!
PL
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T14:42:08-07:00
by fmw42
palobo wrote:Awesome mate!!! That did the trick!
Could I be so bold as to ask for an explanation of what was going wrong and what exactly the fix does.
Cheers and thanks so much for your help!
PL
I don't know what was going wrong, except you commands were way too complicated. So I looked at the two images that seems to make up the result and generated them. I used -flatten rather than -layers merge, which may have been part of your issue.
The first parenthesis, is just your first command. The second is your last two commands simplified (also not the additional +channel) and put into one statement. However, to colorize, I did not use -tint, but rather used -auto-level to stretch the graylevels and then +level-colors somecolor,white to colorize. Once I had those two images with their alpha channels in tact, I just flattened them against a transparent background.
You can now take out the temporary -write ... statements as those temp images were only to figure out what you were doing and how best to recreate it.
see
http://www.imagemagick.org/Usage/color_ ... vel-colors
http://www.imagemagick.org/Usage/layers/#flatten
Fred
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T14:46:40-07:00
by palobo
Fred, you are an IM god amongst men!
Thanks to your help I have finally managed to produce the end result I was aiming for. Now all I need is some fine tuning and I'm set to go.
Thanks so much for your prompt help!
Cheers,
Pedro
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T17:20:06-07:00
by anthony
the -layers merge and -flatten should not be an issue. The only difference is in how they calculate the composition canvas, and in this case all images are the same size and offset, so there should be no difference.
In any case as the zeroth image is a blank canvas, you could junk it, and then you only have two images to compose together!
Most of the problems probably stem from using -channel A but not using the corresponding +channel when finished. Basically it has very far reaching effects that you may not be aware off! In fact it will probably have even more effects in the future!
I noticed that the last examples removed the need for a very restrictive -channel setting.
And while -respect-parenthesis does take care of that problem, I generally never liked to rely on it as \( .. \) was always ment to only be image sequence stacking, not for the handling of settings.
Re: Flatten or merge removes image. Help!!
Posted: 2011-05-23T18:27:05-07:00
by fmw42
Anthony is correct about this. So I have modified my last suggestion to clean it up. Note the +channel that I had already added in the previous version. That was the key as Anthony points out. The first xc:none image is not really needed at the end (but saves typing it twice by using -clone 0), nor the respect-parenthesis. I had added them just to be safe while testing and did not test again without them after I had cleaned up your original examples. So here is the cleaner version.
convert -size 150x150 xc:none \
\( -clone 0 -fill none -stroke black -strokewidth 1 -draw "arc 10,10 130,130 102,280" -channel RGBA -blur 0x4 -write arc1.png \) \
\( -clone 0 -stroke black -strokewidth 3 -draw "arc 10,10 130,130 80,102" -channel A -blur 0x2 +channel -auto-level +level-colors "#24acff,white" -write arc2.png \) \
-delete 0 -background none -flatten arc.png