Sorry guys.  I should realize that not everyone is following my plot :)

This is the same script / process you guys helped me with a week or two ago.
 I am running GIMP on a Windows machine.  I have a directory of XCF files
that I want to export to JPG.  I have a batch-save-as-jpg script-fu to do
this.  The script-fu is invoked from a PowerShell script.  That PowerShell
launches the GIMP batch processor and passes in the script-fu function,
scaling percentage, and a file glob.

##########################################################
#
#   START SCRIPT-FU
#
##########################################################
(define (batch-save-as-jpg pattern resize)
(let* (
(filelist (cadr (file-glob pattern 1)))
(fileparts)
(jpgname "")
(filename "")
(image 0)
(newimage 0)
(drawable 0)
(x1 0)
(x2 0)
(y1 0)
(y2 0)
(width 0)
(height 0)
(selection-bounds 0)
)
 (gimp-message-set-handler 2)
(gimp-message "Preparing to act on the following files")
(gimp-message pattern)
 (while (pair? filelist)
 ; set filename to the name of the current file in the glob
(set! filename (car filelist))
(gimp-message "The current file is: ")
(gimp-message filename)

; set jpgname by tokenizing on "." and taking everything but the last part
(set! fileparts (strbreakup filename "."))
(set! fileparts (butlast fileparts))
(set! jpgname (string-append (unbreakupstr fileparts ".") ".jpg"))
(gimp-message "The new filename will be: ")
(gimp-message jpgname)
 ; set image from the file, and then get the first layer and set it to
newimage
(gimp-message "Loading File.")
(set! newimage (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))

; scale the image
(gimp-message "Scaling the Image.")
; From the Resize %, calculate the new coordinates
 ; Select all so we can calculate the image size
(gimp-selection-all newimage)

(gimp-message "Getting the Image Size")
; Get the image size and store in x1, x2, y1, and y2
(set! selection-bounds (gimp-selection-bounds newimage))
(set! x1 (cadr selection-bounds))
(set! y1 (caddr selection-bounds))
(set! x2 (- (cadr (cddr selection-bounds)) x1))
(set! y2 (- (caddr (cddr selection-bounds)) y1))

; De-select the selection
(gimp-selection-none newimage)

(gimp-message "Calculating the new width and height.")
; Calculate the image width, height
(set! width (- x2 x1))
(set! height (- y2 y1))
 (set! width (* width resize))
(set! height (* height resize))
 (set! width (/ width 100))
(set! height (/ height 100))
 (gimp-message "The new width is: ")
(gimp-message (number->string  width))
 (gimp-message "The new height is: ")
(gimp-message (number->string height))

; set drawable to the newimage
(gimp-message "Setting the Drawable.")
(set! drawable (car (gimp-image-flatten newimage)))
 ; Scale the image to the new width and height
(gimp-drawable-transform-scale drawable 0 0 width height 0 2 0 3 0)
; Crop the image down to the new scaled size
(gimp-image-crop newimage width height 0 0)
; Re-display the cropped image
(gimp-displays-flush)

; Remove any existing selections
(gimp-selection-none newimage)
  ; save the drawable from newimage as jpgname
(gimp-message "Saving the new file.")
(gimp-file-save RUN-NONINTERACTIVE newimage drawable jpgname jpgname)
(set! filelist (cdr filelist))

)
    )
  )

##########################################################
#
#   END SCRIPT-FU
#
##########################################################


##########################################################
#
#   START POWERSHELL
#
##########################################################

$Resize = 10
$SourcePath = "c:\test\xcf"
$GimpifiedSourcePath = $SourcePath -replace("\\", "\\")
$Gimp = "gimp-2.6.exe"
$GimpParams = @("-i", "-b",
"`"(batch-save-as-jpg\`"$GimpifiedSourcePath\\*.*\`" $Resize)`"", "-b",
"`"(gimp-quit 0)`"")

$p = [diagnostics.process]::Start($Gimp, $GimpParams)
$p.WaitForExit()

##########################################################
#
#   END POWERSHELL
#
##########################################################

The Powershell is waiting for the GIMP process to complete before it
continues the script.  This is a problem becomes whenever that GIMP command
finishes, it leaves a hanging command-prompt window open that is waiting for
a key press before it will close.  This causes the PowerShell to stop
executing.

This is not standard behavior on Windows.  Other commands run this way would
briefly launch a command-prompt, execute, complete, and that command prompt
closes on its own.  If it's not part of Script-Fu, perhaps it's part of GIMP
batch mode?  If it's not GIMP that's waiting for input, perhaps it's a flag
set when launching the executable that tells Windows if it could close the
command prompt.  I don't really know where to look for this.

On Sun, Aug 1, 2010 at 12:00 PM,
<gimp-user-requ...@lists.xcf.berkeley.edu>wrote:

>
>
> Message: 5
> Date: Sun, 01 Aug 2010 11:01:07 -0400
> From: Kevin Cozens <ke...@ve3syb.ca>
> Subject: Re: [Gimp-user] Suppressing the "press any character to close
>        this window" message in Script-Fu
> To: gimp-user <gimp-user@lists.xcf.berkeley.edu>
> Message-ID: <4c558c33.9030...@ve3syb.ca>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Dillon wrote:
> > I've written a series of scripts to automate GIMP's script-fu batch
> > processor.  Right now I'm working on starting up multiple asynchronous
> GIMP
> > processes.
> >
> > The problem I'm having right now is with the interactive "press any
> > character to close this window" message that appears when GIMP finishes
> > processing a piece of Script-Fu.
>
> I don't believe the message has anything to do with Script-Fu. The message
> about "press any character..." sounds like a message from a machine running
> the Windows operating system and it wants to close a window that was opened
> to run a program and that program has now terminated.
>
> You can get more help if you would provide more information about your
> batch processing method and how you are invoking GIMP to run Script-Fu
> scripts.
>
_______________________________________________
Gimp-user mailing list
Gimp-user@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-user

Reply via email to