RSS/Atom feed Twitter
Site is read-only, email is disabled

Help scripting transform and copy/paste for photobooth automation?

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

3 of 3 messages available
Toggle history

Please log in to manage your subscriptions.

Help scripting transform and copy/paste for photobooth automation? Jason Yau 08 Dec 09:21
  Help scripting transform and copy/paste for photobooth automation? saulgoode@flashingtwelve.brickfilms.com 08 Dec 17:12
Help scripting transform and copy/paste for photobooth automation? Jason Yau 09 Dec 09:09
Jason Yau
2009-12-08 09:21:21 UTC (about 15 years ago)

Help scripting transform and copy/paste for photobooth automation?

All,

I'm new to script-fu, and brushing up on my rusty Scheme, which I haven't used in about 15 years!

I'm trying to write a script that will help me automate creating a photobooth-like experience. I have a template with a space for 4 images, and some captured images that I want to scale down and copy/paste into the template.

Here is my code, which oddly, which alternates between working properly, throwing an error about a bad drawable ID, and saving the template without the transformed, pasted image.

Also, any tips on an appropriate way to pass 4 filename arguments to the script (as i will eventually be running it on the command line) would be much appreciated!

(define (script-fu-create-filmstrip) (let*
(
; open the template
(image
(car
(gimp-file-load
RUN-NONINTERACTIVE
"c:\\photobooth strip.jpg"
"c:\\photobooth strip.jpg"
)
)
)

(drawable (car (gimp-image-get-active-layer image) )
)

; open captured image
(cap1
(car
(gimp-file-load
RUN-NONINTERACTIVE
"C:\\Img0014.jpg"
"C:\\Img0014.jpg"
)
)
)

(cap1-d (car (gimp-image-get-active-layer cap1) )
)

(sel-float)

)

; scale down captured image
(gimp-image-resize cap1 563 368 0 0)

(gimp-selection-all cap1)

(gimp-edit-copy cap1)

(gimp-rect-select
image
20
20
563
368
REPLACE
0
0
)

; Paste captured image
(set! sel-float (car (gimp-edit-paste drawable FALSE)))

; Anchor the selection (gimp-floating-sel-anchor sel-float)
(gimp-selection-none image)

(gimp-image-flatten
image
)

(set! drawable (car (gimp-image-get-active-layer image) )
)

(gimp-file-save
RUN-NONINTERACTIVE
image
drawable
"c:\\test.jpg"
"c:\\test.jpg"
)
)
)

(script-fu-register
"script-fu-create-filmstrip" ;func name "Film Strip" ;menu label "Edits the filmstrip file and replaces\ the placeholder boxes with camera images" ;description "Author" ;author "copyright 2009" ;copyright notice "December 7, 2010" ;date created "" ;image type that the script works on )
(script-fu-menu-register "script-fu-create-filmstrip" "/Xtn/Photobooth")

Any help to this Gimp scripting newbie would be much appreciated!

saulgoode@flashingtwelve.brickfilms.com
2009-12-08 17:12:43 UTC (about 15 years ago)

Help scripting transform and copy/paste for photobooth automation?

The greatest problem with your code is that 'gimp-image-resize' does NOT scale the image to a different size, it merely changes the canvas size of the image. If you want to scale your "captured" image, you should use 'gimp-image-scale' or 'gimp-image-scale-full'.

Also, there is not much point to performing a rectangle select on the target image. I suspect that your intent in doing so is to have the upper-left corner of the pasted buffer align with the upper-left corner of the selection; however, this is not how 'gimp-edit-paste' works.

Instead, you should change the offsets of the floating selection after pasting:

(set! sel-float (car (gimp-edit-paste drawable FALSE))) (gimp-layer-set-offsets sel-float 20 20) (gimp-floating-sel-anchor sel-float)

As long as your copy buffer is the proper size, there is no need to perform a rectangle select of the targeted region. However, if you'd rather be absolutely certain that nothing outside the targeted region gets modified, you should select the region and use the Paste Into option of 'gimp-edit-paste' (it is still necessary to change the offsets).

(gimp-rect-select image 20 20 563 368 REPLACE 0 0) (set! sel-float (car (gimp-edit-paste drawable TRUE))) (gimp-layer-set-offsets sel-float 20 20) (gimp-floating-sel-anchor sel-float)

Quoting Jason Yau :

All,

I'm new to script-fu, and brushing up on my rusty Scheme, which I haven't used in about 15 years!

I'm trying to write a script that will help me automate creating a photobooth-like experience. I have a template with a space for 4 images, and some captured images that I want to scale down and copy/paste into the template.

Here is my code, which oddly, which alternates between working properly, throwing an error about a bad drawable ID, and saving the template without the transformed, pasted image.

*SNIPPED*

Jason Yau
2009-12-09 09:09:27 UTC (about 15 years ago)

Help scripting transform and copy/paste for photobooth automation?

Many thanks! Your advice was VERY helpful and saved many hours of head banging on the wall.

After some more edits, I've got my script working perfectly. My only remaining question now is if there is a way to disable the Gimp Output cmd window that appears in Windows XP when running in batch mode. I plan to set it up as an automated job, and I don't want windows being flooded with cmd windows that say "Press a key to close this window". Any way to disable the window or have it close automatically when the script finishes?

------------------------------

Message: 3 Date: Tue, 08 Dec 2009 11:12:43 -0500 From: saulgoode@flashingtwelve.brickfilms.com Subject: Re: [Gimp-user] Help scripting transform and copy/paste        for        photobooth automation?
To: gimp-user@lists.XCF.Berkeley.EDU Message-ID:
       
Content-Type: text/plain;       charset=ISO-8859-1;     DelSp="Yes";        format="flowed"

The greatest problem with your code is that 'gimp-image-resize' does NOT scale the image to a different size, it merely changes the canvas size of the image. If you want to scale your "captured" image, you should use 'gimp-image-scale' or 'gimp-image-scale-full'.

Also, there is not much point to performing a rectangle select on the target image. I suspect that your intent in doing so is to have the upper-left corner of the pasted buffer align with the upper-left corner of the selection; however, this is not how 'gimp-edit-paste' works.

Instead, you should change the offsets of the floating selection after pasting:

  (set! sel-float (car (gimp-edit-paste drawable FALSE)))   (gimp-layer-set-offsets sel-float 20 20)   (gimp-floating-sel-anchor sel-float)

As long as your copy buffer is the proper size, there is no need to perform a rectangle select of the targeted region. However, if you'd rather be absolutely certain that nothing outside the targeted region gets modified, you should select the region and use the Paste Into option of 'gimp-edit-paste' (it is still necessary to change the offsets).

  (gimp-rect-select image 20 20 563 368 REPLACE 0 0)   (set! sel-float (car (gimp-edit-paste drawable TRUE)))   (gimp-layer-set-offsets sel-float 20 20)   (gimp-floating-sel-anchor sel-float)