Variable argument in a string

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
User avatar
A-KouZ1
Posts: 3
Joined: 2018-05-05T16:36:01-07:00
Authentication code: 1152

Variable argument in a string

Post by A-KouZ1 »

I'm trying to create a thin border around image edge which has margin 16px from its size:

Code: Select all

convert Original\0_0.png -bordercolor none -border 16  -fill none -stroke red -strokewidth 1 -draw "rectangle 0,0 %%w%%,%%h%%" 0_0.png
But it is ended up with error:

Code: Select all

convert Original\0_0.png -bordercolor none -border 16  -fill none -stroke red -strokewidth 1 -draw "rectangle 0,0 %w%,%h%" 0_0.jpg
convert: non-conforming drawing primitive definition `rectangle' @ error/draw.c/DrawImage/3401.
I expect that this is an error when reading %w% but not treated as variable.

What to do to make this works out?

This code runs through batch, so I need escape %w% with %%w%%
ImageMagick v7 - Windows 10
Last edited by A-KouZ1 on 2018-05-05T17:02:34-07:00, edited 1 time in total.
muccigrosso
Posts: 64
Joined: 2017-10-03T10:39:52-07:00
Authentication code: 1151

Re: Variable argument in a string

Post by muccigrosso »

%w, not %w% and magick instead of convert for v 7 functionality.

Not sure it does what you want, but at least no errors for me.
User avatar
A-KouZ1
Posts: 3
Joined: 2018-05-05T16:36:01-07:00
Authentication code: 1152

Re: Variable argument in a string

Post by A-KouZ1 »

Oh, that's works out, thanks! 😃
But, however, I can't use lastx and lasty.
I decided to replace w,h with lastx,lasty.
where lastx=w-1; lasty=h-1

There are solution?
User avatar
A-KouZ1
Posts: 3
Joined: 2018-05-05T16:36:01-07:00
Authentication code: 1152

Re: Variable argument in a string

Post by A-KouZ1 »

Ok, I had figured the solution myself.

With the use of fx[] in argument:

Code: Select all

magick Original\0_0.png -bordercolor none -border 16  -fill none -stroke red -strokewidth 1 -draw "rectangle 0,0 %%[fx:w-1],%%[fx:h-1]" 0_0.jpg 
Sincerely, thanks anyway. 😀
Post Reply