It is currently Sat Jun 15, 2024 7:23 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Seeking Help with First Multi-File Batch Script
PostPosted: Mon Dec 02, 2019 11:22 pm  (#1) 
Offline
GimpChat Member

Joined: Dec 02, 2019
Posts: 7
GIMP Version: 2.10.14
Operating System: Windows
OS Version: 10
GIMP Experience: Intermediate Level

List any relevant plug-ins or scripts:
goode-mirror-duplicates.scm



Hello, I just discovered batch scripts today for the first time through the official GIMP Batch Mode guide.

I'm looking to do a multiple file operation of thousands of images to mirror them (mirroring the whole image horizontally, yielding an image twice the width in the end). I found a working scm script which is capable of doing this within the GIMP GUI, "goode-mirror-duplicates.scm," which seems like a great start, but I have been trying to figure out how to apply it automatically to a directory of files with no luck. So far, I have attempted to call it from a separate scm file which is just a modified version of the 2nd code in the guide I mentioned.

(define (batch-mirror-dup pattern iterations horizontal vertical workcopy)
  (let* ((filelist (cadr (file-glob pattern 1))))
    (while (not (null? filelist))
           (let* ((filename (car filelist))
                  (image (car (gimp-file-load RUN-NONINTERACTIVE
                                              filename filename)))
                  (drawable (car (gimp-image-get-active-layer image))))
             (script-fu-mirror-dup RUN-NONINTERACTIVE
                                   image drawable iterations horizontal vertical workcopy)
             (gimp-file-save RUN-NONINTERACTIVE
                             image drawable filename filename)
             (gimp-image-delete image))
           (set! filelist (cdr filelist)))))

And running it from cmd like follows:
gimp-2.10 -i -b '(batch-mirror-dup "*.png" 1 TRUE FALSE FALSE)' -b '(gimp-quit 0)'

When running the batch above, nothing happens. CMD simply returns to a new line for me to enter another command. This is my first time with this, and I'm not sure what to do. Any help is appreciated.

EDIT: See post below


Last edited by EC on Mon Dec 02, 2019 11:53 pm, edited 1 time in total.

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: Seeking Help with First Multi-File Batch Script
PostPosted: Mon Dec 02, 2019 11:52 pm  (#2) 
Offline
GimpChat Member

Joined: Dec 02, 2019
Posts: 7
Okay I've made some progress from looking over this forum (I wish this forum turned up in search engine results!)
It turns out I needed to call gimp-console rather than gimp yes?

Now I get this:
Exception code=0xc0000005 flags=0x0 at 0x000000000067DD33. Access violation - attempting to read data at address 0x0000000000000000
Exception code=0xc0000005 flags=0x0 at 0x0000000000401D4D. Access violation - attempting to read data at address 0x0000000000000020


I'm going to keep looking over the threads on this forum as it seems like a great resource though!

EDIT: More progress, figured out that I need to use " instead of ' in CMD. Now a lot of stuff is getting printed out but no dice.
EDIT2: It seems that both my script and also the example script on the official guide end in the same error: "Error: eval: unbound variable: *.png"


Top
 Post subject: Re: Seeking Help with First Multi-File Batch Script
PostPosted: Tue Dec 03, 2019 2:01 am  (#3) 
Offline
GimpChat Member

Joined: Dec 02, 2019
Posts: 7
Following a stackoverflow post, ".png" needs to be changed to `.png` and it is correct to have two ' surrounding the parentheses
In the end, the code is: "D:\Program Files\GIMP 2.8\bin\gimp-console-2.10" -i -b '(batch-mirror-dup `*.png` 1.0 TRUE FALSE FALSE)' -b '(gimp-quit 0)'

The new issue is CMD Reports "batch command executed successfully" but the files are unchanged.

EDIT: This seems to be the case with the example code too. Is it that I'm not defining a directory?
EDIT2: Installed 2.8 and tried with it for same result


Top
 Post subject: Re: Seeking Help with First Multi-File Batch Script
PostPosted: Tue Dec 03, 2019 4:25 am  (#4) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
The official guide to writing scripts is incorrect for Windows command-lines.

You cannot use single-quotes on the command line.

Try this:
"D:\Program Files\GIMP 2.8\bin\gimp-console-2.10" -i -b "(batch-mirror-dup \"*.png\" 1.0 TRUE FALSE FALSE)" -b "(gimp-quit 0)"


Kevin


Top
 Post subject: Re: Seeking Help with First Multi-File Batch Script
PostPosted: Thu Dec 05, 2019 12:39 am  (#5) 
Offline
GimpChat Member

Joined: Dec 02, 2019
Posts: 7
Hey paynekj, that looks to have solved my issue with the example code not working! Now I just need to figure out what's wrong with my code specifically, as it (unsurprisingly) didn't work for my code since it's my first attempt. Thank-you!


Top
 Post subject: Re: Seeking Help with First Multi-File Batch Script
PostPosted: Thu Dec 05, 2019 3:34 am  (#6) 
Offline
GimpChat Member

Joined: Dec 02, 2019
Posts: 7
Alright so I've made good progress with the code. It does actually mirror an image now which is cool, but the problem is it only mirrors the first one for some reason. I'm guessing it's an issue with the logic but I've followed the logic and I'm not sure where. Can anyone spot the mistake? I've attached the file.


Attachments:
File comment: modified version of goode mirror dup
batch-mirror-dup.scm [4.06 KiB]
Downloaded 102 times
Top
 Post subject: Re: Seeking Help with First Multi-File Batch Script
PostPosted: Thu Dec 05, 2019 8:40 am  (#7) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Your problem may be that when you get to gimp-file-save you're saving image instead of work-image, which makes a difference if you've set workcopy to TRUE

Kevin


Top
 Post subject: Re: Seeking Help with First Multi-File Batch Script
PostPosted: Thu Dec 05, 2019 10:10 pm  (#8) 
Offline
GimpChat Member

Joined: Dec 02, 2019
Posts: 7
Thanks Kevin, good call. I changed that now but it still has the same behavior of only doing the operation to the first file though (I was running workcopy as false anyways, planning to remove that part of the code). Any other ideas? I think it might have something to do with the filelist interaction with the while loop but I don't know why.

EDIT: I've determined the while loop is working correctly. It seems to be going to every file and doing stuff but not saving maybe?


Top
 Post subject: Re: Seeking Help with First Multi-File Batch Script
PostPosted: Fri Dec 06, 2019 7:15 am  (#9) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
I've edited the script to make it match how I like the code to look, and I've removed workcopy. I suspect that your problem may have been something to do with the undo mechanism, which I've also changed and now the script seems to work.

;
; The GIMP -- an image manipulation program
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
;
; Mirror layer script  for GIMP 2.4
; Created by Saul Goode
;
; Tags: layer, mirror
;
; Author statement:
;
;
; --------------------------------------------------------------------
; Distributed by Gimp FX Foundry project
; --------------------------------------------------------------------
;   - Changelog -
;
; --------------------------------------------------------------------
;
;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;    (at your option) any later version.
;
;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.
;
;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (script-fu_kjp24_mirror-dup work-image layer iterations horizontal vertical)
  (let*
   (
     (new-layer 0)
     (orig-width 0)
     (orig-height 0)
   )
   (gimp-image-undo-group-start work-image)
   (gimp-selection-none work-image)
   (while (> iterations 0)
     (set! layer (car (gimp-image-get-active-layer work-image)))
     (if (> (car (gimp-image-get-layers work-image)) 1)
      (set! layer (car (gimp-image-merge-visible-layers work-image EXPAND-AS-NECESSARY)))
     )
     (if (= horizontal TRUE)
      (begin
        (set! new-layer (car (gimp-layer-copy layer 1)))
        (gimp-image-add-layer work-image new-layer -1)
        (set! orig-width (car (gimp-drawable-width new-layer)))
        (set! orig-height (car (gimp-drawable-height new-layer)))
        (gimp-layer-resize new-layer (* 2 orig-width) orig-height 0 0)
        (set! new-layer (car (gimp-drawable-transform-flip-simple new-layer ORIENTATION-HORIZONTAL TRUE orig-width 0)))
        (gimp-image-resize-to-layers work-image)
        (if (> (car (gimp-image-get-layers work-image)) 1)
         (set! layer (car (gimp-image-merge-visible-layers work-image EXPAND-AS-NECESSARY)))
        )
      )
     )
     (if (= vertical TRUE)
      (begin
        (set! new-layer (car (gimp-layer-copy layer 1)))
        (gimp-image-add-layer work-image new-layer -1)
        (set! orig-width (car (gimp-drawable-width new-layer)))
        (set! orig-height (car (gimp-drawable-height new-layer)))
        (gimp-layer-resize new-layer orig-width (* 2 orig-height) 0 0)
        (set! new-layer (car (gimp-drawable-transform-flip-simple new-layer ORIENTATION-VERTICAL TRUE orig-height 0)))
        (gimp-image-resize-to-layers work-image)
      )
     )
     (set! iterations (- iterations 1))
   )
   (gimp-selection-none work-image)
   (if (> (car (gimp-image-get-layers work-image)) 1)
     (set! layer (car (gimp-image-merge-visible-layers work-image EXPAND-AS-NECESSARY)))
   )
   (gimp-displays-flush)
    (gimp-image-undo-group-end work-image)
  )
)

(define (batch-mirror-dup pattern iterations horizontal vertical)
  (let*
    (
     (filelist (cadr (file-glob pattern 1)))
   )
    (while (not (null? filelist))
      (let*
       (
         (filename (car filelist))
        (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
        (layer (car (gimp-image-get-active-layer image)))
      )
      (gimp-message (string-append "Processing... " filename))
        (script-fu_kjp24_mirror-dup image layer iterations horizontal vertical)   
        (set! layer (car (gimp-image-get-active-layer image)))
       (gimp-file-save RUN-NONINTERACTIVE image layer filename filename)
       (gimp-image-delete image)
     )
      (set! filelist (cdr filelist))
   )
  )
)

(script-fu-register "script-fu_kjp24_mirror-dup"
                    "Mirror Dup..."
                    "Mirror Duplication"
                    "Me"
                    "Me"
                    "2019.12.06"
                    "*"
                    SF-IMAGE      "Image"      0
                    SF-DRAWABLE         "Drawable"      0
               SF-ADJUSTMENT "Iterations" '(1 1 32 1 10 0 1)
               SF-TOGGLE "Horizontal" TRUE
               SF-TOGGLE "Vertical" FALSE
                   )
               
(script-fu-menu-register "script-fu_kjp24_mirror-dup" "<Image>/Script-Fu")


Top
 Post subject: Re: Seeking Help with First Multi-File Batch Script
PostPosted: Fri Dec 06, 2019 7:58 pm  (#10) 
Offline
GimpChat Member

Joined: Dec 02, 2019
Posts: 7
Thank-you so much Kevin!! It works!


Top
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) converting 32 bit images to 8 bit using batch script

5

No new posts Attachment(s) Batch export all opened images script for GIMP [Update]

13

No new posts Attachment(s) Script for selecting, cropping the selection and saving the file

8

No new posts Seeking Marbles.

8

No new posts Attachment(s) Seeking method restoring colour of old photo

24



* Login  



Powered by phpBB3 © phpBB Group