-2

im trying to add a caption below each image using the following Imagemagick command:

convert 3_1.jpg   -background Khaki  label:"@3_1.txt" -gravity Center -append 3_1_text.png

This works fine and got this:

figure with label below

Basically i use an image file named e.g. xxx.jpg and add the caption from a text file with the same name (xxx.txt). What i want to do now is the same process but for a bunch of jpg files in a folder, using a batch process. I have the following folder:

folder with JPGs and text files

So i want to make a batch file that process each image with his respective txt file, and ideally save all the outputs in a specific directory.

Thank you in advance, and best regards,

Jorge

  • 1
    Simple for command to iterate all the files in a directory: `FOR %%G IN (*.jpg) DO command`. The variable `%%G` will hold the file name. – Squashman Oct 13 '21 at 14:52
  • The simple solution as suggested by Squashman is: `for %%G in (*.jpg) do "C:\ImageMagick\Path\convert.exe" "%%G" -background Khaki label:"@%%~nG.txt" -gravity Center -append "%%~nG_text.png"` – Mofi Oct 13 '21 at 17:34

1 Answers1

-1

i modified the code of the third answer and it did the job:

@ECHO OFF FOR %%G IN (*.jpg) DO convert %%G   -background Khaki  label:"@%%~nG.txt" -gravity Center -append "%%~nG_text.png"

it works like charm!

  • If any JPEG file contains a space or one of these characters ``&()[]{}^=;!'+,`~`` it would not work anymore like a charm. Why have you not used exactly the code as posted by me with `"C:\ImageMagick\Path\convert.exe"` modified to the full qualified file name (drive+path+name+extension) of `convert` on your hard disk enclosed in `"`? – Mofi Oct 14 '21 at 18:22
  • ah. i simply wanted to maintain my style of code for no particular or important reason. Didnt know about the space or special characters case situation, however, all the JPEG that i will use dont have spaces or the special characters. Anyways, ty for the acclaration! Really appreciated! c: – Coke Lobos Oct 14 '21 at 22:58