Re: IM Question (Scripting)
Anthony Thyssen <[email protected]> Fri, 15 Oct 2010 15:05:35 +1000
| Newsgroups | gmane.comp.video.image-magick.user |
|---|---|
| Message-ID | <20101015150535.54bf006d@wraith> |
On Thu, 14 Oct 2010 17:39:40 +1100 [email protected] wrote: | Hi Anthony, | | Thanks for your work with ImageMagick. I use it nearly everyday. But, my | ignorance is getting the best of me and I am getting tired of creating | spreadsheets of line commands to run like: | | convert -background "transparent" -density 300 -size 1248x -gravity Center | -matte -transparent "" -fill black -font | /Users/mike/Library/Fonts/varsity_regular.ttf -pointsize 200 label:'00' | -depth 24 Varsity-00.png | convert -background "transparent" -density 300 -size 1248x -gravity Center | -matte -transparent "" -fill black -font | /Users/mike/Library/Fonts/varsity_regular.ttf -pointsize 200 label:'01' | -depth 24 Varsity-01.png | convert -background "transparent" -density 300 -size 1248x -gravity Center | -matte -transparent "" -fill black -font | /Users/mike/Library/Fonts/varsity_regular.ttf -pointsize 200 label:'02' | -depth 24 Varsity-02.png | | You show some examples on the Text to Image Handling page of the IM site | that refer to a text file or msg. generator but is there a way I can go | through a names file and generate an image from each line individually vs. | the entire file? | | Thanks for your help. | This would be a good question to put in the IM forum web site, and you will probably get many responses. Basically you are wanting to adventure to the next level beyond ImageMagick into shell scripting, or alternative PHP or (heven forbid sic) DOS batch scripting!!!! Here I will give you a solution using Shell scripting... Assuming the strings '00' '01' in the above are NOT just a sequence of numbers but can be any string... Then.... First create a file of the strings wanted. This could be a single column CVS file from a spreadsheet, seeing you mentioned that. For example file "names.txt" contains... -------8<-------- Anthony Fred George John -------8<-------- How you need to create a loop. that will read one string at a time from this file. and rung the command with that string "$name". -------8<-------- while read name; do convert -fill black -background None -density 300 -pointsize 200 \ -font /Users/mike/Library/Fonts/varsity_regular.ttf \ -size 1248x -gravity Center label:"$name" \ -depth 8 Varsity-"$name".png done < file.txt -------8<-------- Note that the variable "$name" (yes the quotes are important) appears twice, once for the label and once for the output filename. I also took the liberty to correct a few things. -depth is the size of a color value and is generally either 8 or 16. It is not a image 'depth' like 24. See IM Examples Depth http://www.imagemagick.org/Usage/basics/#depth This will do want you want.... To take it to the next step.... You can create a small script call "create_label" containing the IM command, and using "$1" instead of "$name"... -------8<-------- #!/bin/bash convert -fill black -background None -density 300 -pointsize 200 \ -font /Users/mike/Library/Fonts/varsity_regular.ttf \ -size 1248x -gravity Center label:"$1" \ -depth 8 Varsity-"$1".png -------8<-------- and make it executable using a command like chmod +x create_label then run the loop like this -------8<-------- while read name; do /path/to/script/create_label "$name" done < names.txt -------8<-------- Or even use a tricky command such as xargs -1 < names.txt /path/to/script/create_label All this is known as shell scripting, and you can piece together a lot of simple commands to generate much more complex commands. As one bash scripting starting point see... Wizard Boot Camp, Part One: Linux, Shells & Commands http://www.linux-mag.com/id/4038 There are lots of other web pages on leanring Shell or Bash scripting some probably a lot better than what I gave, asking on the forum should give you a number of good pointers... Later I myself like to refer to this for all the advanced features... Advanced Bash-Scripting Guide http://www.tldp.org/LDP/abs/html/index.html Anthony Thyssen ( System Programmer ) <[email protected]> -------------------------------------------------------------------------- DM: "I'll let you live if you roll lower then 3 on 4d6" PC: "Okay that's better... Hey!" -------------------------------------------------------------------------- Anthony's Castle http://www.cit.griffith.edu.au/~anthony/