I have started to work with VB script and ImageMagick recently. I wrote a short VB script to convert PNG images to TIF. It worked fine when the images were in the same directory as the script and no pathnames were included. Now we need to run the script with import and archive directory parameters. The script no longer does the conversion and the issue appears to be with the pathnames. Example of the final command called: "C:\Program Files\ImageMagick\Convert" -adjoin "C:\Images\484912282013141D_0_FRONT.PNG" "C:\Images\484912282013141D_1_BACK.PNG" "C:\Images\484912282013141C_0_FRONT.PNG" -threshold 60% -density 118 "C:\Images\484912282013141.TIF"
When this line is pasted in a command window, it works. But it doesn't work when the script is run. The script only works if no pathnames are included. Does anyone have an idea about how I can get this to work? In the script, that example is assigned to cmdLine and executed with "oshell.Run "cmd /C " & cmdline, 0".
Appreciate any help I can get.
Laura
Use full pathname of image with Convert
Re: Use full pathname of image with Convert
Are you getting any error messages? 'It doesn't work' does not tell us that much. Does the path to your image include spaces or is the path really 'C:\Images'?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Use full pathname of image with Convert
Try using forward slash / or double backslash \\.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Use full pathname of image with Convert
In principle for proper use of IM 6, the images should be read before applying an operator. Do you really want -adjoin or do you really mean -append.
Re: Use full pathname of image with Convert
There are no errors. The TIF image file is just not created. The path may or may not include spaces so each filename is surrounded by double quotes. The example path I provided is one I am using for testing.dlemstra wrote:Are you getting any error messages? 'It doesn't work' does not tell us that much. Does the path to your image include spaces or is the path really 'C:\Images'?
It is necessary to use -adjoin to create a multi-image Tif file. I don't believe there is any problem with the settings used with the Convert command. The example I presented creates the converted image file when run by itself in a command window. It creates the converted image file from within the script when the script is run from the image directory and no pathnames are included. It does not create the converted image file when pathnames are used in the script.fmw42 wrote:In principle for proper use of IM 6, the images should be read before applying an operator. Do you really want -adjoin or do you really mean -append.
Using either forward slash or double backslash gives the same result. The converted image file is created when run directly from the command prompt but not when the script is run.snibgo wrote:Try using forward slash / or double backslash \\
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Use full pathname of image with Convert
I suggest you find the minimum script that shows the problem. Paste that here, between [ code ] and [ /code].
snibgo's IM pages: im.snibgo.com
Re: Use full pathname of image with Convert
Test.tif is created. Quoted_test.tif is not.
Code: Select all
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = WScript.CreateObject("WSCript.shell")
IMConvert = oshell.ExpandEnvironmentStrings("%PROGRAMFILES%") & "\ImageMagicK\Convert"
progFolder = objFSO.GetParentFolderName(Wscript.ScriptFullName)
importFolder = "C:\Images\"
imgDocs = "img_1.PNG"
imageArg = " -threshold 60% -density 118 "
rootFilename = "quoted_test"
imgPNGs = Chr(34) & importFolder & imgDocs & Chr(34)
cmdline = Chr(34) & IMConvert & Chr(34) & " " & imgPNGs & imageArg & Chr(34) & importFolder & rootFilename & ".TIF" & Chr(34)
oshell.run "cmd /C " & cmdline, 0
WScript.Echo "Quoted Test" & Chr(10) & cmdLine
rootFilename = "test"
imgPNGs = importFolder & imgDocs
cmdline = Chr(34) & IMConvert & Chr(34) & " " & imgPNGs & imageArg & importFolder & rootFilename & ".TIF"
oshell.run "cmd /C " & cmdline, 0
WScript.Echo "Unquoted Test" & Chr(10) & cmdLine
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Use full pathname of image with Convert
I dunno. It isn't an ImageMagick problem. If you use exec instead of run, you can echo the stderr from each command. Some experimentation shows that if you don't quote IMConvert, or you don't quote the output file, it works.
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Use full pathname of image with Convert
Cracked it. See "cmd /?" for how it processes quotes. It may "strip the leading character and remove the last quote character on the command line".
Alternative solutions:
1. Add /S to cmd, eg
2. There is no need to use cmd at all. cmd is a shell, but you don't need it. Eg:
Solution 2 is faster and more elegant.
Alternative solutions:
1. Add /S to cmd, eg
Code: Select all
Set objExecObject = oshell.exec ("cmd /S /C " & cmdline)
Code: Select all
Set objExecObject = oshell.exec (cmdline)
snibgo's IM pages: im.snibgo.com