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?".
cd directory_containing_wordfile.txt
wordlist=`cat wordfile.txt`
for word in $wordlist; do
convert canvas.jpg \
\( -size 100x100 -background white -font arial.ttf \
-fill black label:"$word" -trim +repage -depth 8 \) \
-gravity center -composite $word.jpg
done
cd directory_containing_wordfile.txt
wordlist=`cat wordfile.txt`
for word in $wordlist; do
convert canvas.jpg \
\( -size 100x100 -background white -font arial.ttf \
-fill black label:"$word" -trim +repage -depth 8 \) \
-gravity center -composite $word.jpg
done
Yay! It works perfect I was tinkering with the windows code PandoraBox gave, and i was pretty hopeless with my attempts to make it work.
Thank you Fred. Couldn't get my stuff done without the immense help from you folks over here. Appreciated very much always! Please have a great weekend and Cheers
Thanks fred, but like you say always if people post the version and operating system saves a huge amount of work however I can't complain when I see a comparison code for different platforms..
cd directory_containing_wordfile.txt
wordlist=`cat wordfile.txt`
for word in $wordlist; do
convert canvas.jpg \
\( -size 100x100 -background white -font arial.ttf \
-fill black label:"$word" -trim +repage -depth 8 \) \
-gravity center -composite $word.jpg
done
Slight alternative for the shell script loop reading full lines from a file (with spaces)
One line per processing loop.
cd directory_containing_wordfile.txt
wordlist=`cat wordfile.txt`
for word in $wordlist; do
convert canvas.jpg \
\( -size 100x100 -background white -font arial.ttf \
-fill black label:"$word" -trim +repage -depth 8 \) \
-gravity center -composite $word.jpg
done
But i am unable to generate images with full lines and spaces. This is what i have tried below. Could anyone please let me know what i am doing wrong? Thank you
while read line; do
convert canvas.jpg \
\( -size 100x100 -background white -font arial.ttf \
-fill black label:"$line" -trim +repage -depth 8 \) \
-gravity center -composite "$line".jpg
done < wordfile.txt
Your mistake was you used "$word" when you were reading "$line".
NOTE: this will also create filenames with spaces, and punctuation. And while computers can handle such filenames, they make it harder to deal with later. I suggest the following...
cd directory_containing_wordfile.txt
wordlist=`cat wordfile.txt`
for word in $wordlist; do
convert canvas.jpg \
\( -size 100x100 -background white -font arial.ttf \
-fill black label:"$word" -trim +repage -depth 8 \) \
-gravity center -composite $word.jpg
done
Slight alternative for the shell script loop reading full lines from a file (with spaces)
One line per processing loop.
For is bad option for read lines from file. While is better
but
This is safer option
while IFS= read -r line || [ -n "$line" ]; do
echo "$line"
done <file
The -r option to read prevents backslash interpretation (usually used as a backslash newline pair, to continue over multiple lines or to escape the delimiters). Without this option, any unescaped backslashes in the input will be discarded. You should almost always use the -r option with read.
And || [ -n "$line" ] to make it work with files without a newline at end.If there is such file shell does not read last line from the file.
To preserve white space at the beginning or the end of a line, specify IFS= (with no value) immediately before the read command. After reading is completed, the IFS returns to its previous value in shell variable.