Creating a batch of images containing a large text

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?".
Post Reply
TomVal
Posts: 2
Joined: 2015-04-10T12:16:24-07:00
Authentication code: 6789

Creating a batch of images containing a large text

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Creating a batch of images containing a large text

Post 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
snibgo's IM pages: im.snibgo.com
TomVal
Posts: 2
Joined: 2015-04-10T12:16:24-07:00
Authentication code: 6789

Re: Creating a batch of images containing a large text

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating a batch of images containing a large text

Post by fmw42 »

xabier
Posts: 1
Joined: 2015-04-20T09:07:23-07:00
Authentication code: 6789

Re: Creating a batch of images containing a large text

Post 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 ....
tardus
Posts: 1
Joined: 2015-10-13T23:30:11-07:00
Authentication code: 1151

Re: Creating a batch of images containing a large text

Post 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.
Post Reply