It is currently Sat Apr 20, 2024 5:05 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Using filenames in the console
PostPosted: Tue Mar 31, 2015 9:27 am  (#1) 
Offline
New Member

Joined: Mar 31, 2015
Posts: 4
Hello,

I'm a newbie here sorry if the questions are stupid but I spent hours reading a lot of stuff about Gimp Scripts but can't find an answer to some questions.
I'm currently using the Script-Fu console before I write a real script to get used to the commands

I need to cut the same selection on 1000+ pictures, resize the selection and paste it on other pictures
First I saved my selection to a path and exported the path to a file

I managed to make this command work after importing a saved SVG path :
(gimp-path-to-selection 12 "MyPath" 0 FALSE FALSE FALSE FALSE)

1) I'd like to use a command/script to import my saved SVG file
commands such as :
(gimp-vectors-import-from-file image filename merge scale)
(gimp-path-import image filename merge scale)

But no matter how I write the filename, I get "no such file or directory"
Do I need to put the file in a specific folder ?
I tried to write "c:\tmp\path1.svg" but it doesn't work

2) Using the console, is there an easier way to refer to a picture than to look at the ID of the picture ?

Thanks


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Using filenames in the console
PostPosted: Tue Mar 31, 2015 10:17 am  (#2) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
1) Two things you could try for your filenames:

"c:\\tmp\\path1.svg"

or

"c:/tmp/path1.svg"

2) No - you have to use the ID

Kevin


Top
 Post subject: Re: Using filenames in the console
PostPosted: Tue Mar 31, 2015 10:37 am  (#3) 
Offline
New Member

Joined: Mar 31, 2015
Posts: 4
Thank you very much, the second format works perfectly !

Do you know which procedure corresponds to the "Scale Tool" (scale layer, selection or path)
Is it "gimp-item-transform-scale" ?

In this case, how do I refer to my selection ? (this procedure needs an "item")


Top
 Post subject: Re: Using filenames in the console
PostPosted: Tue Mar 31, 2015 10:46 am  (#4) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
passager57 wrote:
Thank you very much, the second format works perfectly !

Do you know which procedure corresponds to the "Scale Tool" (scale layer, selection or path)
Is it "gimp-item-transform-scale" ?

In this case, how do I refer to my selection ? (this procedure needs an "item")


Yes I think gimp-item-transform-scale is what you want and gimp-image-get-selection will get you the selection ID

Kevin


Top
 Post subject: Re: Using filenames in the console
PostPosted: Tue Mar 31, 2015 12:10 pm  (#5) 
Offline
New Member

Joined: Mar 31, 2015
Posts: 4
I just tested gimp-item-transform-scale : it scales the selection but not the actual picture inside it
Am I missing something ?
Thanks


Top
 Post subject: Re: Using filenames in the console
PostPosted: Tue Mar 31, 2015 12:28 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
That's because a selection is just an area - it's not connected to any of the layers in your image until you use it to copy/cut/paste etc from/to a particular layer.

Rather than trying to second guess what you are trying to do (which happens far too often here), how about you explain the process you are trying to implement.

Kevin


Top
 Post subject: Re: Using filenames in the console
PostPosted: Tue Mar 31, 2015 1:01 pm  (#7) 
Offline
New Member

Joined: Mar 31, 2015
Posts: 4
Sure, here you go :

I'm trying to make game cards

I have a lot of 1024X768 pictures and I need to cut the exact same zone each time to get the character, resize it (680X980) and paste it centered on a background picture (size 822x1122)

A picture should be more explicit than my poor english

Image

these pics are just examples, I'm not using street fighter stuff for my card game ;)


Top
 Post subject: Re: Using filenames in the console
PostPosted: Tue Mar 31, 2015 1:50 pm  (#8) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
That's a good description.

So after making your selection, you need to copy that area from the first image...

So use gimp-edit-copy which will copy the area described by the selection

Then you can paste it as a floating selection (gimp-edit-paste) into the second image and then re-scale the floating-selection, which you already know about.

You may need to move the floating selection and then you will have to anchor it.

Kevin


Top
 Post subject: Re: Using filenames in the console
PostPosted: Tue Mar 31, 2015 4:56 pm  (#9) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4736
passager57 wrote:
2) Using the console, is there an easier way to refer to a picture than to look at the ID of the picture ?

Thanks

If you write your script in Python (which is somewhat simpler than Scheme), then most of the API will use the complete "objects" and not the IDs, plus it is usually a bit simpler to get at data. For instance, making the 5th layer of the image invisible can be as simple as:
image.layers[4].visible=False


Choose wisely :)

_________________
Image


Top
 Post subject: Re: Using filenames in the console
PostPosted: Tue Mar 31, 2015 5:01 pm  (#10) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4736
paynekj wrote:
That's a good description.

So after making your selection, you need to copy that area from the first image...

So use gimp-edit-copy which will copy the area described by the selection

Then you can paste it as a floating selection (gimp-edit-paste) into the second image and then re-scale the floating-selection, which you already know about.

You may need to move the floating selection and then you will have to anchor it.

Kevin


It will be much faster to:

- Duplicate the image with the character
- Crop the image around the character
- Enlarge the canvas
- Import the background layer

Using the clipboard in scripts is a bit slow, and momentarily kills the clipboard for other applications in the system, so it's best avoided.

_________________
Image


Top
 Post subject: Re: Using filenames in the console
PostPosted: Tue Mar 31, 2015 5:50 pm  (#11) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
ofnuts wrote:
Using the clipboard in scripts is a bit slow, and momentarily kills the clipboard for other applications in the system, so it's best avoided.

The clipboard does seem to be a bit slow, though I can't imagine why that should be so (I will need to investigate further). As to killing the clipboard, one can use as many named clipboards as one wants, and never affect the "global buffer" clipboard (see the "Edit->Buffer" submenu or the *-named-* PDB procedures).

passenger57, here is some code for you to peruse. The challenging bit is to transfer the selection in the template to the source images (to copy the character). My code copies the selection to a (named) buffer, which is then copied to a channel in the source image and loaded as a selection (GIMP does not allow pasting directly into the selection mask).

There are other ways to do this, such as your use of paths, but I wished to emphasize that a selection is just a grayscale drawable that itself can be saved, copied, scaled, etc.

Note that my code uses the global buffer, which is generally a bad idea for a script (scripts should typically used named buffers); however, since you would be running the code in batch mode, there is no chance of the code interfering with what a user might be doing.
; sel-file - filename of an XCF that is the same size as the source
;            pictures and with its selection positioned correctly
; bg-file -  the filename of the image containing the background file
;            (basically a blank "card")
; inset-pattern - wildcard pattern for filenames of the source pictures
;
(define (process-inset sel-file bg-file inset-pattern)
  (define (fetch-selection xcf-file)
    (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE xcf-file xcf-file)))
           (sel (car (gimp-selection-save image))))
      (gimp-selection-none image)
      (let ((buffer (car (gimp-edit-named-copy sel "tmpsel"))))
        (gimp-image-delete image)
        buffer)))

  (let ((bg-image (car (gimp-file-load RUN-NONINTERACTIVE bg-file bg-file)))
        (sel-buffer (fetch-selection sel-file)))
    (let loop ((filenames (cadr (file-glob inset-pattern 1)))
               (seq 1))
      (unless (null? filenames)
        (let* ((image (catch #f (car (gimp-file-load RUN-NONINTERACTIVE
                                                     (car filenames)
                                                     (car filenames) ))))
               (layer (car (gimp-image-get-active-layer image)))
               (new-sel (car (gimp-selection-save image))))
          (gimp-floating-sel-anchor (car (gimp-edit-named-paste new-sel
                                                                sel-buffer
                                                                FALSE)))
          (gimp-image-select-item image CHANNEL-OP-REPLACE new-sel)
          (gimp-edit-copy layer)
          (gimp-image-delete image)
          (let* ((card-image (car (gimp-image-duplicate bg-image)))
                 (card-layer (car (gimp-image-get-active-layer card-image)))
                 (floated (car (gimp-edit-paste card-layer FALSE))))
            (gimp-layer-scale floated 680 980 TRUE)
            (gimp-layer-set-offsets floated (/ (- 822 680) 2) (/ (- 1122 980) 2))
            (gimp-floating-sel-anchor floated)
            (let ((filename (string-append "output-"
                                           (number->string seq)
                                           ".png")))
              (gimp-file-save RUN-NONINTERACTIVE card-image card-layer filename filename))
            (gimp-image-delete card-image)))
          (loop (cdr filenames)
                (succ seq))))
    (gimp-image-delete bg-image)
    (gimp-buffer-delete sel-buffer)))

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Working with unicode filenames

0

No new posts GIMP 2.10 console etc Macbook

0

No new posts Attachment(s) Cannot run test script-fu script via console

7



* Login  



Powered by phpBB3 © phpBB Group