Gimptalk - Premier Gimp Community: Excel to gimp plugin/script? - Gimptalk - Premier Gimp Community

• 2 Pages
• 1
• 2

Excel to gimp plugin/script?

#1blackmesa5

• Member
• Group: Members
• Posts: 12
• Joined: 22-April 09

Posted 01 January 2010 - 05:38 PM

Hey guys. Im wondering of anyone knows of any plugins/scripts that would allow me to use text data from an Excel spreadsheet to fill out text boxes in a gimp image. Im working on a card game and it would make my life much easier if I could have all the relevant data in an excel spreadsheet, and then feed that data into GIMP so that the text in column 1 would go in a certain text box in the image, and so on, and then have the script save that image file and move onto the next one. Does anyone know of anything like this?
0

#2blackmesa5

• Member
• Group: Members
• Posts: 12
• Joined: 22-April 09

Posted 03 January 2010 - 11:32 PM

Hmmmm no responses. Im not really familar with the GIMP plugin/scripting capabilities, is this even remotely possible or am I barking up the wrong tree?
0

#3PhotoComix

• GT Senior Moderator
• Group: Senior Moderators
• Posts: 11,288
• Joined: 13-June 05

Posted 04 January 2010 - 12:14 AM

i never used excel so i have no idea

Quote

use text data from an Excel spreadsheet to fill out text boxes in a gimp image.

Anyway I believe you may found better tool then gimp to do thing with text,...gimp may do nice things with pixels but text are not made with pixels
(when text is converted in pixels gimp may come into play and create cool FX, but then txt info are automatically discarded and text become editable only as a image )

More i doubt actually gimp may deal with multi lines text...if you may select and copy from excel side the text one line at time then you may pass the text to gimp as input...
but if you hope Gimp able to automatically find the best size for the text to fill a box you risk delusion

it will make sense if you want some peculiar bitmap fx applied to your text or its background (but again that destroy all text data, after human may still read the text, but for the computer become a image.)
0

#4blackmesa5

• Member
• Group: Members
• Posts: 12
• Joined: 22-April 09

Posted 04 January 2010 - 02:13 AM

Right now I have no need to edit the text after it is created, so the fact that GIMP will convert my text into an image format is fine. After the desired text is put into the GIMP image, Im just going to print everything out, so there is no further editing. The only reason GIMP is involved is because the rest of the design has been done in it, the borders and colors, etc... I dont want GIMP to pick the best text format/style/size/etc... I cant figure that out on my own, I just dont want to have to go through the process of clicking on the same 2 text boxes and enter slightly different text for 100 images.

I did some digging into GIMP batch processing and script commands. I see that an operation can be done to multiple images in a folder. Im thinking I could use the text command and figure out the locations/dimensions of each text box so that the text would always be in the correct places. The only thing I didn't come across is any file Input/Output commands for the scripting language, so that I could load and parse the data from the spreadsheet file. Is this something I missed or does it not exist?

Is there anyway to work around this? I have some programming knowledge, so given the functions I could figure it out, but Im not advanced enough to figure out how to get different programs to "talk" so to speak.
0

#5saulgoode

• Retired Staff
• Group: Retired Staff
• Posts: 5,324
• Joined: 22-August 05

Posted 04 January 2010 - 03:49 AM

I wrote a script about a month ago in response to a request on the GIMP Users mailing list which might prove useful as a starting point for approaching your problem. The script addressed the problem of adding people's names to graphical badges (or nametags) and producing a single image containing all of the badges (for printing). You can find links to the script, some sample files, and read a description here.

If you provide further specifics and some example files then I'd be willing to assist.

Ideally, the Excel-produced text file should use space- or tab-delimited values (CSV can be made to work, but requires much more effort).

The image file(s) should be in XCF format and contain the graphic layer plus two layers which are the size and location of the regions where the text is to be placed.
Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#6blackmesa5

• Member
• Group: Members
• Posts: 12
• Joined: 22-April 09

Posted 07 January 2010 - 01:59 AM

Wow thats gonna be really helpful, thanks soooo much. Im having some trouble running it, it seems to be looking for the seuss.xcf in the home/username/badges folder? What folder is this referring to? I looked through the code but cant find the command to change that location.
0

#7blackmesa5

• Member
• Group: Members
• Posts: 12
• Joined: 22-April 09

Posted 11 January 2010 - 09:49 PM

Saul is there a way I could contact you to further discuss this script?
0

#8PhotoComix

• GT Senior Moderator
• Group: Senior Moderators
• Posts: 11,288
• Joined: 13-June 05

Posted 11 January 2010 - 10:20 PM

PM should work clicking on the name on top of the avatar should redirect you to a page , there one of option is send a Private Message
But are you sure the argument has to be kept private ?
Of course is your chose the PM feature is always available
0

#9saulgoode

• Retired Staff
• Group: Retired Staff
• Posts: 5,324
• Joined: 22-August 05

Posted 12 January 2010 - 07:48 AM

blackmesa5 said:

Wow thats gonna be really helpful, thanks soooo much. Im having some trouble running it, it seems to be looking for the seuss.xcf in the home/username/badges folder? What folder is this referring to? I looked through the code but cant find the command to change that location.

The path to each of the badge templates is specified in the data file (example.data). /home/username/badges is just an example directory, any directory could have been specified (in the data file).

Quote

Saul is there a way I could contact you to further discuss this script?

Just send me a PM.
Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#10blackmesa5

• Member
• Group: Members
• Posts: 12
• Joined: 22-April 09

Posted 12 January 2010 - 11:26 PM

Hahaha wow missed the PM button somehow, and I was looking.
0

#11blackmesa5

• Member
• Group: Members
• Posts: 12
• Joined: 22-April 09

Posted 20 January 2010 - 06:15 AM

Ok so here's a sample file that would demonstrate what Im talking about. The Gimp file is my image template which contains some image data, borders, etc.... All of the colors and images and stuff I can edit on my own without a script. What I would like a script to do is open the style of template, fill in 3 different text boxes with data from the spread sheet and save it as a specific filename. If it cant save it as a specific file name than just an incremental number is fine.

In the data file I put columns to correspond with the template type, the two text boxes, the number box and the file name. The data for column 1 is the template file name/location, column 2 is the text to go in box 1, column 3 is the data to go in box 2, column 4 is the 2 digit number to go in the 3rd text box, and the final column is the desired filename. Does this make sense? Is it even possible?

Thanks so much for everything.

template: http://dl.dropbox.co...%20temp%201.xcf
data: http://dl.dropbox.co...52446/Book1.txt
0

#12saulgoode

• Retired Staff
• Group: Retired Staff
• Posts: 5,324
• Joined: 22-August 05

Posted 21 January 2010 - 03:28 AM

I have your files but I don't think I'll get a chance to do anything until Saturday.
Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#13saulgoode

• Retired Staff
• Group: Retired Staff
• Posts: 5,324
• Joined: 22-August 05

Posted 07 February 2010 - 09:28 PM

Save the following code to a file in your scripts directory (with a .scm extension).

Run the code from the command line with something like:

gimp -i -b "(process-excel-file \"C:\path\to\csv-file.txt\" \"C:\path\to\template-directory\\\" \"C:\path\to\output-directory\\\" )" -b "(gimp-quit 0)"

I don't run Windows so you may encounter problems.

(define (process-excel-file csv-filename template-path output-path)
(define (get-text-layer-with-name image name)
(let (
(layer's (vector->list (cadr (gimp-image-get-layers image))))
(layer 0)
)
(while (pair? layer's)
(set! layer (car layer's))
(if (and (gimp-drawable-is-text-layer layer)
(string=? (car (gimp-drawable-get-name layer)) name))
(set! layer's nil)
(begin
(set! layer's (cdr layer's))
(set! layer 0)
)
)
)
layer
)
)
(let* (
(str "")
)
(while (and (not (eof-object? ch)) (not (equal? #\newline ch)))
(set! str (string-append str (make-string 1 ch)))
(set! ch (read-char inport))
)
(if (eof-object? ch)
nil
str
)
)
)
(let* (
(template 0)
(inport (open-input-file csv-filename))
(ch 0)
(line "")
(template-filename "")
(output-filename "")
(layer 0)
(field's nil)
)
(when inport
(read-line inport) ; skip first line
(set! line (read-line inport))
(while (not (null? line))
(set! field's (strbreakup line (make-string 1 #\tab)))
(set! template-filename (string-append template-path (car field's) ".xcf"))
(set! template (car (gimp-xcf-load 0 template-filename template-filename)))
(gimp-image-undo-disable template)
(set! layer (get-text-layer-with-name template "Text 1"))
(gimp-text-layer-set-text layer (cadr field's))
(set! layer (get-text-layer-with-name template "Text 2"))
(gimp-text-layer-set-text layer (caddr field's))
(set! layer (get-text-layer-with-name template "01"))
(gimp-text-layer-set-text layer (cadddr field's))
(set! output-filename (string-append output-path
(car (strbreakup (car (cddddr field's)) "\r"))
; ^^^  strip trailing MS-DOS RET  ^^^
".xcf"))
(gimp-xcf-save 0 template layer output-filename output-filename)
(gimp-image-delete template)
(set! line (read-line inport))
)
(close-input-port inport)
)
)
)

Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#14blackmesa5

• Member
• Group: Members
• Posts: 12
• Joined: 22-April 09

Posted 10 February 2010 - 02:43 AM

I created a folder for all the files at location C:\Template. In there I put file "Book1" which is the tab delimited txt file, and the gimp template. I ran it in the GIMP command line and get this error.

> gimp -i -b "(process-excel-file \"C:\Template\Book1.txt" \"C:Template\\\" \"C:\Template\\\" )" -b "(gimp-quit 0)"
Error: eval: unbound variable: gimp
0

#15saulgoode

• Retired Staff
• Group: Retired Staff
• Posts: 5,324
• Joined: 22-August 05

Posted 10 February 2010 - 05:34 AM

blackmesa5 said:

I created a folder for all the files at location C:\Template. In there I put file "Book1" which is the tab delimited txt file, and the gimp template. I ran it in the GIMP command line and get this error.

> gimp -i -b "(process-excel-file \"C:\Template\Book1.txt" \"C:Template\\\" \"C:\Template\\\" )" -b "(gimp-quit 0)"
Error: eval: unbound variable: gimp

That example was intended to be run from the Windows command prompt. If you are going to run the command from within GIMP's Script-fu console, you should use:

(process-excel-file "C:/Template/Book1.txt" "C:/Template/" "C:/Template/" )

Note that I replaced the backslashes with forward slashes -- Script-fu should automatically use the appropriate separator for your operating system.
Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#16blackmesa5

• Member
• Group: Members
• Posts: 12
• Joined: 22-April 09

Posted 11 February 2010 - 02:59 AM

Ok I thought that might be the case. Anyway, I ran it from the gimp script fu console and when it runs it returns "#t" and doesnt create a file.

This is my template file http://dl.dropbox.co...52446/Book1.txt but I've also tried it with and without the .xcf after body (which is the template file) and also making the spread sheet a .csv file. It never returns anything other than "#t" nor does it make a file. I created the script file and named it exactly, "process-excel-file.scm".

Thanks for all this help!
0

#17saulgoode

• Retired Staff
• Group: Retired Staff
• Posts: 5,324
• Joined: 22-August 05

Posted 11 February 2010 - 03:41 AM

blackmesa5 said:

Ok I thought that might be the case. Anyway, I ran it from the gimp script fu console and when it runs it returns "#t" and doesnt create a file.

Your original data file had the headers in the first row (the script skips over the first line in the data file), and it also had a fifth column which contained the output filename (the script uses this filename).

Style       Text 1         Text 2  Numbers      Filename
body temp 1 abcdefghi      xyz     10           card1
body temp 2 xya            abc     8            card2


Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#18blackmesa5

• Member
• Group: Members
• Posts: 12
• Joined: 22-April 09

Posted 11 February 2010 - 08:25 PM

saulgoode said:

blackmesa5 said:

Ok I thought that might be the case. Anyway, I ran it from the gimp script fu console and when it runs it returns "#t" and doesnt create a file.

Your original data file had the headers in the first row (the script skips over the first line in the data file), and it also had a fifth column which contained the output filename (the script uses this filename).

Style       Text 1         Text 2  Numbers      Filename
body temp 1 abcdefghi      xyz     10           card1
body temp 2 xya            abc     8            card2


Well that was a silly mistake. D'oh!

Just ran it, works P-E-R-F-E-C-T-L-Y! Thank you so much!
0

#19blackmesa5

• Member
• Group: Members
• Posts: 12
• Joined: 22-April 09

Posted 18 February 2010 - 10:43 PM

Found one minor problem. If I make the folder of the finished files a sub folder of the template folder such as:

(process-excel-file "C:/Template/Book1.txt" "C:/Template/" "C:/Template/Folder" )

It puts all finished files in the Template folder and adds "Folder" to the beginning of their filename. Not a huge deal, just wasnt sure if I was doing something wrong.
0

#20saulgoode

• Retired Staff
• Group: Retired Staff
• Posts: 5,324
• Joined: 22-August 05

Posted 19 February 2010 - 12:26 AM

blackmesa5 said:

Found one minor problem. If I make the folder of the finished files a sub folder of the template folder such as:

(process-excel-file "C:/Template/Book1.txt" "C:/Template/" "C:/Template/Folder" )

It puts all finished files in the Template folder and adds "Folder" to the beginning of their filename. Not a huge deal, just wasnt sure if I was doing something wrong.

You need to have a solidus at the end of the folder paths:

(process-excel-file "C:/Template/Book1.txt" "C:/Template/" "C:/Template/Folder/" )

Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0