Page 1 of 1

+swap doesn't seem to be working?

Posted: 2017-04-20T11:17:27-07:00
by prabab
Hi!

I'm using the latest version of ImageMagick and trying to add a simple shadow effect to a text. However, even when I copy the examples straight from the official website, it seems that the created layers won't swap (when they're generated as two files each looks correct, but not together).

I believe this might stem in my lack of understanding of how to treat IM syntax when it's called through PHP.

I'm trying to run this code:

Code: Select all

exec("magick convert -background none -fill white -font Candice -pointsize 48  label:A -trim \( +clone -background black  -shadow 100x3+0+0 -channel A -level 0,50% +channel \) +swap +repage -gravity center -composite \"{$sourceDir}{$output}\" ");
However, the result looks like this, despite the example page stating something entirely different. And I'm not talking about the font.

Image

My guess would be that created image layers don't swap for some reason. What am I doing wrong? :<

Re: +swap doesn't seem to be working?

Posted: 2017-04-20T11:41:30-07:00
by snibgo
Does the command give an error? Do you check for errors?

I don't use PHP. Why have you escaped the parentheses?

Re: +swap doesn't seem to be working?

Posted: 2017-04-20T11:43:11-07:00
by GeeMack
prabab wrote: 2017-04-20T11:17:27-07:00However, the result looks like this, despite the example page stating something entirely different. And I'm not talking about the font. [...] My guess would be that created image layers don't swap for some reason. What am I doing wrong?
Using IM 7.0.5-4 on Windows, and converting your command just enough to run at a command prompt...

Code: Select all

magick convert -background none -fill white -font arial -pointsize 48 label:A ^
   -trim ( +clone -background black -shadow 100x3+0+0 -channel A -level 0,50% +channel ) ^
   +swap +repage -gravity center -composite output.png
... I get the result I would expect, the white "A" composited over its black shadow.

Maybe as a test try leaving out the "-composite" and see if your command creates the two output images, one white "A" and a second of just the shadow. Try it with and without the "+swap" to see what's happening before the composite operation.

Re: +swap doesn't seem to be working?

Posted: 2017-04-20T11:49:21-07:00
by prabab
snibgo wrote: 2017-04-20T11:41:30-07:00 Does the command give an error? Do you check for errors?
It didn't give me any errors.
I don't use PHP. Why have you escaped the parentheses?
That's how it's presented in examples, I guess. Also, some paragraph about "clone" function says it needs to be in parentheses.
... I get the result I would expect, the white "A" composited over its black shadow.
...yes, after removing the escape chars it seems to be working, thank you!

Re: +swap doesn't seem to be working?

Posted: 2017-04-20T11:52:01-07:00
by Bonzo
I don't use PHP. Why have you escaped the parentheses?
You need to escape them on Linux machines - possibly mac as well?

Re: +swap doesn't seem to be working?

Posted: 2017-04-20T12:06:04-07:00
by snibgo
prabab wrote:That's how it's presented in examples, I guess.
In bash examples, yes. Linux and Mac (or any bash) command lines, yes, they need parentheses to be escaped. But PHP double-quoted strings don't, according to a manual: http://php.net/manual/en/language.types.string.php