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)))