Page 1 of 1

Help w/ syntax of VB command

Posted: 2016-03-03T06:11:39-07:00
by rocketshiptech
I absolutely love imageMagic, I’ve been using it in some of my programs for almost 10 years now. Problem is: I only write one line of code for it every 3 to 5 years, up so I’ve never actually *learned* how to use it. I stumble through it, with a lot of cutting and pasting, and a little help from you guys.

Here’s my current problem: I have a data table with a list of file paths, and xy coordinates. (actually just X coordinates, the Y coordinate will always be 0) is my goal is to create a long strip of an image with each of these images spaced these distances apart.

The data looks like this:

Filepath, XY
c:\bmp\A.jpg 10,0
c:\bmp\B.jpg 350,0
c:\bmp\C.jpg 752,0

And I would loop through it with VB code to something like this:

With objImageList
Do while not .eof
ImgMagCmdTxt = ImgMagCmdTxt & ", " & .Filepath & ", [" & .XY & "]"

which would create the string *
"c:\bmp\A.jpg, [10,25], c:\bmp\B.jpg [10,350], c:\bmp\C.jpg, [10,752]"

which we would then use in a IM COM object command something like this:
strConvertResult = objImgMag.convert(ImgMagCmdTxt, destfilepath)

*Now I absolutely realize that is the wrong syntax for this string! But it is (I think) the data we need and it is in *a* string.

My question is: what would be the correct syntax for that string? Specifically, what about the quote marks?

The ImageMagick command line utility, and the ImageMagick COM object seem to have different requirements when it comes to quote marks, all the parameters in VB need to be in closed quote marks, but some need quote marks the inside of a quote marks, (I usually use & Chr(34) & for that). This is why the examples web page have never work for me.

To repeat: my goal is to create a long strip of an image with each of these images spaced these distances apart.


Re: Help w/ syntax of VB command

Posted: 2016-03-03T06:40:00-07:00
by snibgo
There are many variations of command that will do this. One is to "+append" many images together, where every other image is "xc:" at the width of the required gap and only 1 pixel high. So the command could be:

Code: Select all

convert A.jpg xc:none[10x1+0+0] B.jpg xc:none[350x1+0+0] C.jpg +append out.png
Sorry, I can't help much with VB. Like most languages, string constants need to be quoted. If there are no quotes, VB assumes they are variables.

Command lines (such as bash and Windows CMD) work differently. There, variables have special markings such as $(...) or %...%, and quotes are needed to prevent a space character denoting the end of a token, and similar purposes to prevent the shell from interpreting special characters.

Re: Help w/ syntax of VB command

Posted: 2016-03-03T07:01:47-07:00
by rocketshiptech
This may be all the help I need.
But pls explain the 10x1+0+0 bit.

I'm sure I wasn't clear:
Pic A is 80px tall and 250 px wide, ans should start 10 px away from the left edge. (i.e. starts at XY 10,0)
Pic B is 80px tall and 300 px wide and needs to be 90 px away from pic A. (i.e. starts at XY 350,0)

Re: Help w/ syntax of VB command

Posted: 2016-03-03T07:16:30-07:00
by snibgo
In that case, the command would be:

Code: Select all

convert xc:none[10x1+0+0] A.jpg xc:none[90x1+0+0] B.jpg +append out.png
"xc:none[10x1+0+0]" is an image that is 10 pixels wide and 1 high. It is colour "none", which means it is transparent. So the command will place this 10x1 image, then A.jpg, then a 90x1 image, then B.jpg.

EDIT: corrected.

Re: Help w/ syntax of VB command

Posted: 2016-03-03T07:21:39-07:00
by rocketshiptech
OH! xc:none is THE GAP!
(did you mean to but the 2nd "convert" in there?)

Re: Help w/ syntax of VB command

Posted: 2016-03-03T08:00:31-07:00
by snibgo
Sorry, that was a copy-paste error, now corrected. Thanks.

If you want to use absolute coordinates instead of gaps, this should do it:

Code: Select all

convert ( A.jpg -repage +10+0 ) ( B.jpg -repage +350+0 ) -layers mosaic out.png