script to loop create a bunch of files , text increments on

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
zimbot

script to loop create a bunch of files , text increments on

Post by zimbot »

Friends,
I have done some simple ( scale a dir full of images) things with IM --
But here is something that I am unable to do.

goal :: create 300 pngs , size = 720x480 , each is Black with white text of 1 incrementing to 300 , 0-300.pngs

and of course -- if I knew how to make 10 -- that would be great.

I have tried a linux shell and a win version


--------------------( linix

in a file make300.sh

#!/bin/sh
for i while i<300
do
echo $i
mogrify -normalize \\
-size 720 x 480 \\
-bordercolor yellow -border 5 \\
-fill white \\
-font \\
-*-Times \\
-gravity center \\
-draw 'text 20,20 $i\\
$i.png
$i=$i+1
done




--------------------( win

in a file make300.bat

---

LOAD DLL "CORE_RL_wand_.dll"
CALL DLL "MagickWandGenesis"
m_wand = CALL DLL "NewMagickWand"
if m_wand$ = 0 then NewMagickWand failed
err = CALL DLL "MagickReadImage",m_wand$,"logo:"
if err$ = 0 then the read failed
for i while i<300
do
echo $i
mogrify -normalize \\
-size 720 x 480 \\
-bordercolor yellow -border 5 \\
-fill white \\
-font \\
-*-Times \\
-gravity center \\
-draw 'text 20,20 $i\\

CALL DLL "MagickWriteImage",m_wand$,$i.png
$i=$i+1
CALL DLL "MagickWandTerminus"

----------------

Any assistance would be appreciated !

thanks
z
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: script to loop create a bunch of files , text increments on

Post by anthony »

This was answered, and then some, on the IM mailing list. however technically it was not an IM problem but a shell scripting one.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
zimbot

Re: script to loop create a bunch of files , text increments on

Post by zimbot »

this was most excellently answered (by Alex s )--- I drop it here for others
http://www.nabble.com/Re%3A-loop-to-mak ... 10692.html

Ah, so the xc:black must become a variable color, too. Those are specified
in hexadecimal notation like #rrggbb. For grey, rr, gg, and bb are the
same values, incrementing from 00 (black) to something like 80 (dark
grey), while white would be 255. So we calculate it as 80 * i / 300.
Using printf, we can output these values in hex notation which IM needs.
I also use printf in order to generate names with leading zeros. Let's
make the 300 and 80 variables, too. Which gives this script:

#!/bin/bash

n=300
darkgrey=80

for (( i=0; i < n; i++ ))
do
color=$( printf "%02x" $(( darkgrey * i / n )) )
printf "Creating file %3d with color %s..." $i "$color"
convert -normalize \
-size 720x480 \
-bordercolor yellow \
-border 5 \
-fill white \
-font "Times-New-Roman" \
-gravity center \
-draw "text 20,20 '$i'" \
xc:\#$color$color$color "$( printf "%03d" $i ).png"
printf " OK\n"
done


You may even paste the whole loop (without the #!/bin/bash) into your
terminal, so there is no need to save this script into a file and make it
executable.

Wonko

/// and again -- my thanks to all - zimbot ///
Post Reply