+swap doesn't seem to be working?

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
prabab
Posts: 2
Joined: 2017-04-20T11:10:04-07:00
Authentication code: 1151

+swap doesn't seem to be working?

Post 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? :<
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

Does the command give an error? Do you check for errors?

I don't use PHP. Why have you escaped the parentheses?
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

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

Post 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.
prabab
Posts: 2
Joined: 2017-04-20T11:10:04-07:00
Authentication code: 1151

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

Post 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!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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
snibgo's IM pages: im.snibgo.com
Post Reply