Page 1 of 1

Folder path syntax

Posted: 2017-11-28T10:53:07-07:00
by mikelee33
Hello -

I'm a new ImageMagick user. The one thing I am wanting to do with ImageMagick is giving me problems, and I'm certain it's a syntax error. I have no problems processing single files using "convert", but attempting to correctly specify explicit paths to source and output folders, in order to process entire folders (and repeatedly failing), has led me to ask for assistance.

For my application I am required to specify the full paths to the source and output folders. I've tried numerous variations on this, substituting "*.JPG" with "*.*" or removing it completely:

convert "C:\Users\DELL\Desktop\test\*.JPG" -pointsize 30 -background black -fill white label:@comment.txt -gravity center -append "C:\Users\DELL\Desktop\test\output\*.JPG"

The "output" folder exists in the "test" folder, and "convert.exe" is in the path. Again, single files are no problem, just getting the syntax to specify folder processing is.

Many thanks,
Mike

IM 7.0.6-10 Q16 x86
Windows 10 Pro

Re: Folder path syntax

Posted: 2017-11-28T13:40:40-07:00
by GeeMack
mikelee33 wrote: 2017-11-28T10:53:07-07:00For my application I am required to specify the full paths to the source and output folders. I've tried numerous variations on this, substituting "*.JPG" with "*.*" or removing it completely:

convert "C:\Users\DELL\Desktop\test\*.JPG" -pointsize 30 -background black -fill white label:@comment.txt -gravity center -append "C:\Users\DELL\Desktop\test\output\*.JPG"

The "output" folder exists in the "test" folder, and "convert.exe" is in the path. Again, single files are no problem, just getting the syntax to specify folder processing is.
I can think of at least one way IM7 can do that without relying on other outside commands, but it's probably less complicated to just work that process in a "for" loop. A tiny BAT script might look something like this...

Code: Select all

@echo off

for %%I in ( C:\Users\DELL\Desktop\test\*.JPG ) do (
   convert "%%I" -pointsize 30 -background black -fill white ^
      label:@comment.txt -gravity center -append "C:\Users\DELL\Desktop\test\output\%%~nxI"
)

echo Done.
Save it as a *.bat file and run it in the same directory as your "comment.txt". If you're running from a command prompt instead of a BAT script, a similar command would use single percent signs "%" instead of doubles "%%".

Re: Folder path syntax

Posted: 2017-11-28T15:17:51-07:00
by mikelee33
GeeMack -

Thank you very much for your response, example, and suggestion.

Yes, if I could incorporate all this into a "for' loop in a BAT script I definitely would, although my need is to furnish an "explicit" path, as I am working with variables in an AutoIt script. If I could figure out the logic behind how IM sees and works with folders then I would be all set and could proceed. The thing is IM seems to work with folders quite differently from files. Is this early observation true?

The command line example I furnished earlier is essentially how I would code it in AutoIt, where the full paths are replaced with variables:

RunWait(@ComSpec & " /c " & $PROG & ' "' & GUICtrlRead($FILE) & "\*.JPG" & '"' & " -pointsize 30 -background black -fill white " & "label:@comment.txt" & " -gravity center -append" & ' "' & GUICtrlRead($FILE) & "\output\*.JPG" & '"', "", @SW_HIDE)

Where $PROG = convert.exe

I apologize for bringing another scripting language into this discussion, but essentially it all comes down to how IM needs the output folder and files defined (as I interpret your batch script).

Thanks again

Re: Folder path syntax

Posted: 2017-11-28T15:40:14-07:00
by snibgo
The easiest way to use "convert" is with one file at a time: one input file that converts to one output file. And you need to give the full path to each. No wildcards.

GeeMack has showed how to do that in Windows BAT scripts: the shell script loops through files, calling "convert" for each one.

I'm not familiar with AutoIt, but I expect is has a mechanism to loop through files.

Re: Folder path syntax

Posted: 2017-11-28T15:59:04-07:00
by fmw42
You cannot use wildcards for both input and output with magick/convert. To process a folder of images, you need to use magick mogrify in IM 7 (or just mogrify in IM 6)

cd to directory

Code: Select all

magick mogrify -path path2/existing/folder -format jpg *
will convert every image in the directory to the same name with jpg suffix and put it in path2/existing/folder

see http://www.imagemagick.org/Usage/basics/#mogrify

Re: Folder path syntax

Posted: 2017-11-28T18:05:25-07:00
by mikelee33
Thank you all.

Even though in my intended use and example I wanted to use -append, and that operator is not available for use with mogrify, I have found that I can substitute -annotate to get the information I need onto photos if it means that I can be more easily accomplish my folder processing.

Thanks again for pointing me in a more workable direction.