Page 1 of 1

Creating a batch of images containing a large text

Posted: 2015-04-10T12:26:23-07:00
by TomVal
Hello,

my eyes are anything but good, but I still use them. On a smartphone, I'd like to create contact pictures, which wold contain contact names written with white letters on black background, the letters should be as large as possible.

It looks like ImageMagick has everything I need. I was briefly reading docs section about working with texts, and there's a way to put a text into an image with given directions, where ImageMagick decides the font size as large as possible.

I can prepare a file with texts which would serve as contact names, but I'm not sure how to code a script which would read such a text file and produce series of images with those texts on them. I think it'd be nice to prepare a CSV file.

I'm using Windows 8.1, so maybe I could use a .bat script or a PowerShell script. Unfortunately, I'm not an experienced script coder, so I don't seem to be able to prepare such a script file. Can you help me? Thanks in advance.

Re: Creating a batch of images containing a large text

Posted: 2015-04-10T19:59:05-07:00
by snibgo
For the IM command, "caption:" is useful here.

Having cataracts, I find white characters on a black background easier to read than black on white. You might have a different preference.

This is an ImageMagick forum, not a scripting forum, but the script can be very simple.

Suppose the text file names.csv contains:

Code: Select all

Jo Bee
Aleksandr Isayevich Solzhenitsyn
Bill Williams
Suppose your screen is 300x200 pixels. Windows BAT script:

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
)
This creates file names_0.png, names_1.png and names_2.png:

Image
Image
Image

Re: Creating a batch of images containing a large text

Posted: 2015-04-11T03:12:17-07:00
by TomVal
Many thanks for your help. Yes, this is not a forum about scripting, but I asked here, since ImageMagick is a main tool used in my task, but I was really not sure how to do what i really intended to do. Now I'm trying to fully understand commands used in your script, so I can customize this scripts to my needs.

Re: Creating a batch of images containing a large text

Posted: 2015-04-11T07:24:31-07:00
by fmw42

Re: Creating a batch of images containing a large text

Posted: 2015-04-20T09:12:07-07:00
by xabier
snibgo wrote:For the IM command, "caption:" is useful here.

Having cataracts, I find white characters on a black background easier to read than black on white. You might have a different preference.

This is an ImageMagick forum, not a scripting forum, but the script can be very simple.

Suppose the text file names.csv contains:

Code: Select all

Jo Bee
Aleksandr Isayevich Solzhenitsyn
Bill Williams
Suppose your screen is 300x200 pixels. Windows BAT script:

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
)
This creates file names_0.png, names_1.png and names_2.png:

Image
Image
Image
And the same script for Linux? Please ....

Re: Creating a batch of images containing a large text

Posted: 2015-10-13T23:52:26-07:00
by tardus
Here is a Linux BASH shell script that does the same steps:-

#!/bin/sh

while read TEXT
do
NAME=`echo $TEXT | tr ' ' '_'` # replace spaces with underscores
echo $TEXT " : " $NAME
convert \
-size 300x200 \
-gravity Center \
-background Black -fill White \
caption:"$TEXT" \
$NAME.png
done < text.lis

text.lis contains the text, one line per image.