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

Jump to content

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Excel to gimp plugin/script?

#21 User is offline   nicobu 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 05-July 10

Posted 05 July 2010 - 02:43 PM

Hi guys,

thanks for your work saulgoode. I had the exact same problem and your script helped me very much.

BUT :twisted:

I don't understand why and were not able to find anything in the www about your script not reading some special chars like German Umlaute. I tried printing the chars to the console after they were read and it seems like the read-char function does not even read ä (ä), ö (ö) or ü (ü).

Any ideas?
0

#22 User is offline   saulgoode 

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

Posted 05 July 2010 - 04:29 PM

Unfortunately, I believe the problem is inherent to the TinyScheme interpreter used by GIMP -- its read-char and write-char functions appear to always convert to UTF-8. I encountered this while trying to use Script-fu to write some binary data files and found that 0x00 was not being written.

It is, in my opinion, a severe bug in TinyScheme but that project does not seem to have a way of submitting bug reports. If you need to do this in Script-fu, you might contact GIMP developer Kevin Cozens as he is the main focal point of GIMP's Script-fu development. Alternately, you might consider writing a plug-in using C programming language.
Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#23 User is offline   nicobu 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 05-July 10

Posted 06 July 2010 - 09:04 AM

Arrrgh. I'm not really good at C, Java would be better. :)

Well, ok. I found this tutorial about GIMP plugins.

My first question is: What do I need?

What I think I need is:
- C compiler (included in free Visual Studio Express?) to compile GIMP sources and plugin
- Compile GIMP sources to get gimptool-2.0.exe (or is it anywhere in my standard Win32 GIMP installation?)
- gimptool-2.0.exe + C compiler + libgimp headers (included in GIMP source package?)
- a little C knowledge

What I hope I need is (but partly don't know how to get):
- gimptools-2.0 + libgimp headers to compile the plugin
- a little C knowledge

First way would be quite hard for me. I don't want to download, install and get used to a development IDE just to write a simple C plugin. Is there an easier way to get a C compiler? I found lcc but it seems I need Visual C++ to compile the compiler. Weird... :?:
If second way works could you tell me where I can find gimptools-2.0 and libgimp?

Thanks for your help and sorry for my newbie questions.
0

#24 User is offline   saulgoode 

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

Posted 06 July 2010 - 03:07 PM

nicobu said:

My first question is: What do I need?

Lack of proper development tools is one of the main reasons I do not use Windows. So I can't really help you much with that aspect.



nicobu said:

What I think I need is:
- C compiler (included in free Visual Studio Express?) to compile GIMP sources and plugin
- Compile GIMP sources to get gimptool-2.0.exe (or is it anywhere in my standard Win32 GIMP installation?)
- gimptool-2.0.exe + C compiler + libgimp headers (included in GIMP source package?)
- a little C knowledge

What I hope I need is (but partly don't know how to get):
- gimptools-2.0 + libgimp headers to compile the plugin
- a little C knowledge

Gimptool does not obviate the need for a C compiler and libgimp headers; it uses them to compile plug-ins.


I would recommend starting a new topic outlining what you want to accomplish. Be specific and provide the "big picture" as well as some example data files and expected output files.

To avoid dragging things out over weeks of player "Twenty Questions" I propose you provide the following information to start:
    What is the nature of your task? Are you doing this as a one time thing -- processing a thousand files just this once and never needing to re-do it? Or is it something you will be doing periodically (e.g., once a month)? If to be run more than once, what aspects do you expect to be different from one run to the next.

    The specifications for the input and output files; not just the contents of the files, but what directories are used, what the filenames/templates are, et cetera. This is often the most tedious part of writing scripts or plug-ins and it is impossible for the programmer to know what you want (and unnecessarily complicated to provide for all possible combinations).

    Describe the system upon which you are running and the programs you are using to process the data. If Python is functioning on your system then you might be able to code a plug-in using Python instead of C (there are also extensions for LUA, MONO, PERL, JavaScript, and Java; to varying degrees of support). If you are good at Java programming, you might be able to run GIMP in its "server mode" and send commands to it interactively.

    Provide sample files. Specify file types to be handled and produced.

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

#25 User is offline   goobie 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 13-June 12

Posted 13 June 2012 - 02:02 PM

I expect saulgoode might pop back over here to have a look.... :rolleyes:

I tried this script from a Windows 7 cmd line using Gimp 2.6, and received "batch command experienced an execution error".

Not sure where to start/go with this - changing xcf files with updated text will make my life much easier, as I need to do this about 40 times in a go, about once a month.

Any help appreciated!

The command I ran was : C:\Program Files (x86)\GIMP-2.0\bin>gimp-2.6.exe -i -b "(process-excel-file \"C:\delthis\input.txt\" \"C:\delthis\\\"\"C:\delthis\\\" )" -b "(gimp-quit 0)"

I have in c:\delthis two files -
File 1 - input.txt
Style Text 1 Text 2 Numbers Filename
body temp 1 abcdefghi uuu 10 card5
body temp 1 aefghi vvu 11 card6
body temp 1 abfghi uuwwwu 12 card7

File 2 - body temp 1.xcf

In C:\Users\gary\.gimp-2.6\scripts i have the file process-excel-file.scm
(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
      )
    )
  (define (read-line inport)
    (let* (
        (ch (read-char inport))
        (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)
      )
    )
  )

This post has been edited by goobie: 13 June 2012 - 02:03 PM

0

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic