Page 1 of 1

[solved]How to create multiple images from lines of a text file

Posted: 2020-02-29T11:13:38-07:00
by dav22
Hello;
I am new to imagemagick, I am using imagemagick ver 7.0.9 -q16 on Windows 7 64 bit.

I want to make batch images from line/s of text in a text file.
I have searched the forum, but not found any that I can use.
on https://www.imagemagick.org/discourse-s ... hp?t=27366, there has been batch script posted :

Code: Select all

set NUM=0
for /F "tokens=*" %%A in (names.csv) do (
  %IM%convert ^
    -size 300x200 ^
    -gravity Center ^
    -background Black -fill White ^
    caption:"%%A" ^
    names_!NUM!.png

  set /A NUM+=1
)
I made a csv file with couple of rows of text, and tried the above batch file, I suppose it should make 3 images, each image contains one row of data, but it it dot work, this make only one image and inside the image is a text: %%A,
It does not read data from csv file I guess.
I could not figure out how to make it work,
Here is what I want to do:
lets say I have a text file contains 100 lines of text,
now I want to make one image file from one line of text (or two lines) from this text file,
the text file could contain text this way:
line one of text
line two of text
line three of text
line four of text

after converting, I want to have 4 images, in this example, called, image1.jpg, image2.jpg, image3.jpg, image4.jpg
on image1.jpg should contains: "line one of the text" and on image2.jpg : should be "line two of text" and so on.
can this be done ?
if so please help me,
thanks.

Re: How to create multiple images from lines of a text file

Posted: 2020-02-29T11:41:21-07:00
by snibgo
That is a BAT script. Are you running this as a BAT script, or directly from the command line?

When you run that script, what is the output file named?

Perhaps you need "setlocal enabledelayedexpansion" at the top of the script.

Re: How to create multiple images from lines of a text file

Posted: 2020-02-29T14:15:47-07:00
by dav22
thank you for reply;
I did not tried as bat file, I only tried it on command line with no result,
the output image file called: name_!NUM!.png
this time, I saved it as bat file, and run it, I makes only one image file, and and on it, there is a text which is on line 3 of text file, and the image file name is the same as above: names_!NUM!.png
at least this time there is something to start looking for problem.
thanks

Re: How to create multiple images from lines of a text file

Posted: 2020-02-29T14:46:40-07:00
by snibgo
You need "setlocal enabledelayedexpansion" at the top of the script.

Re: How to create multiple images from lines of a text file

Posted: 2020-02-29T15:04:07-07:00
by dav22
thanks a lot, now it is working