I only got ImageMagick yesterday, and while I've managed to get it to do most of what I want it to do, there's still one thing: Reading from a file.
I know that ImageMagick can read from a plain text file - I fiddled with this a bit, but it just wasn't quite what I wanted. I'm wondering if ImageMagick can read from a table or spreadsheet file of some kind.
What I am trying to do is bulk-make cards for a card game. I have everything set up in the right places, but I still have to go in and change the text manually each time. What I do have is a spreadsheet with each card, its various costs, and its text in different columns, with a new card being on a new row.
Does ImageMagick read from a table file natively?
If it doesn't, what other options are there? I'm fairly new with Ubuntu here, but I'm getting the hang of it. Maybe a shell script to take a csv file, take the row, put it into various files (IE card_title.txt, card_text.txt), then run the image script, then go back and do it again for the next row?
Any help is appreciated
Reading from a table/spreadsheet
Re: Reading from a table/spreadsheet
I tend to use php and would create an array and loop through the array. Thats how I create buttons for websites.
Re: Reading from a table/spreadsheet
I'm not too familiar with PHP, though, and I'd like to be able to do this myself. Mostly for when I want to change it, so that I can do that myself as well
Re: Reading from a table/spreadsheet
If you are not happy using php there must be shell, batch script methods you can use to do something like this:
CSV file:
It would need some work to get what you wanted but you can see the method:
Read the csv file row contents into an array a row at a time and then add the array contents to an image; move onto the next row.
Code: Select all
<?php
// http://php.net/manual/en/function.fgetcsv.php
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, "|")) !== FALSE) {
$num = count($data);
$text = "";
$row++;
for ($c=0; $c < $num; $c++) {
$text .= $data[$c];
}
exec("convert -size 400x100 xc:lightblue -fill black -pointsize 20 -gravity center -annotate +0+0 \"$text\" card$text.jpg");
echo "<br><img src=\"card$text.jpg\"><br />\n";
}
fclose($handle);
}
?>
Code: Select all
day|data|year
01|02|09
02|02|10
Read the csv file row contents into an array a row at a time and then add the array contents to an image; move onto the next row.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Reading from a table/spreadsheet
IM does not read from any special formatted table such as Excel (to my knowledge), but it can read from a space (or other) delimited fields of text data in a plain text file. I have done this a number of times in some of my scripts, but requires some knowledge of unix commands to read the data and parse the fields into variables.
Re: Reading from a table/spreadsheet
Thanks for the help, guys. I've had some help in getting it done via Python