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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Locked
dav22
Posts: 29
Joined: 2020-02-05T09:22:25-07:00
Authentication code: 1152

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

Post 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.
Last edited by dav22 on 2020-02-29T15:05:11-07:00, edited 1 time in total.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com

dav22
Posts: 29
Joined: 2020-02-05T09:22:25-07:00
Authentication code: 1152

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

Post 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

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

You need "setlocal enabledelayedexpansion" at the top of the script.
snibgo's IM pages: im.snibgo.com

dav22
Posts: 29
Joined: 2020-02-05T09:22:25-07:00
Authentication code: 1152

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

Post by dav22 »

thanks a lot, now it is working

Locked