It is currently Mon Apr 15, 2024 7:40 am


All times are UTC - 5 hours [ DST ]


Switch to mobile style

Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Unable to do simple batch process from cmd
PostPosted: Thu Aug 06, 2015 1:08 pm  (#1) 
Offline
New Member

Joined: Aug 06, 2015
Posts: 3
(Under Windows 7 x64)

I originally tried to use BIMP to apply a cutout effect to a folder but FU-cutout is one of the few that doesn't appear in the plug-in's list. I read somewhere that was because I hadn't install GIMP while customizing to allow compatibility with older plug-in and I de/reinstalled to try and fix this to no avail. So I decided to use script-fu instead but find myself unable to make it work out through the command line despite my code being virtually the same as several found online.

(define (hmd-batch-stylize pattern colours smoothness)
   (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)))
               )
            (gimp-brightness-contrast drawable 35 40)
            (FU-cutout RUN-NONINTERACTIVE
                               image drawable colours smoothness TRUE)
            (gimp-file-save RUN-NONINTERACTIVE
                         image drawable filename filename)
            (gimp-image-delete image)
          )
       (set! filelist (cdr filelist))
   )
))


(I also register the script but for the sake of simplicity I won't add this code here). Then I open the command line and write

gimp -i -b '(hmd-batch-stylize "C:\Users\User\Desktop\3\*jpg" 32 1)' -b '(gimp-quit 0)'


in the gimp directory (I tried the directory where my files are but gimp isn't recognized as a command there). The gimp console starts up, fails to execute a bunch of dlls and a folder (all part of GMIC) with the mention "Exec format error", then I get two "Batch command completed successfully" at which point the command line freezes until I close it.

I searched online for days hoping to find a solution but no one seems to have the same problem as I do so no solution has worked yet. Help would be greatly appreciated.

PS: I thought of instead creating a script that would appear in BIMP and act as a middle-man to access the FU-cutout but I can't find how to pass the current image/filename being used by BIMP as an argument. If anyone knows how, I feel that might be my simplest way of working around this problem.


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: Unable to do simple batch process from cmd
PostPosted: Thu Aug 06, 2015 2:38 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
Hmm.. sounds like you've got several problems here.

First of all, the reason you can't invoke FU-cutout from BIMP is that it won't allow you to choose any Gimp procedure containing the string "-cut" in the name. In fact, there are a lot of names BIMP won't allow, as defined by this filter list:
      "^(?!.*(?:"
         "plug-in-bimp|"
         "extension-|"
         "-get-|"
         "-set-|"
         "-is-|"
         "-has-|"
         "-get-|"
         "-print-|"
         "file-glob|"
         "twain-acquire|"
         "-load|"
         "-save|" // TODO: remove it for next feature "enable saving plugins"
         "-select|"
         "-free|"
         "-help|"
         "-temp|"
         "-undo|"
         "-copy|"
         "-paste|"
         "-cut|"
         "-channel|"
         "-buffer|"
         "-register|"
         "-metadata|"
         "-layer|"
         "-selection|"
         "-brush|"
         "-gradient|"
         "-guide|"
         "-parasite|"
         "gimp-online|"
         "gimp-progress|"
         "gimp-procedural|"
         "gimp-display|"
         "gimp-context|"
         "gimp-fonts|"
         "gimp-palette|"
         "gimp-path|"
         "gimp-pattern|"
         "gimp-vectors|"
         "gimp-quit|"
         "gimp-plugins|"
         "gimp-gimprc|"
         "temp-procedure"

So you could just rename the procedure (in file FU_artist_cutout.scm) to one of your own choosing (eg. "FU-mycutout") and invoke that instead.
However, if you also want to invoke other procedures such as (gimp-brightness-contrast) you're better off using a "middle-man" script anyway.

When BIMP invokes your middle-man script the image ID and active layer ID are simply the first two parameters supplied to the script/plugin, the same as if you invoked the script/plugin manually from the Gimp menu.
So your middleman script should be something like:
(define (FU-mycutout image drawable brightness contrast colours smoothness)

  (gimp-image-undo-group-start image)

  (gimp-brightness-contrast drawable brightness contrast)
  (FU-cutout image drawable colours smoothness TRUE)

  (gimp-image-undo-group-end image)
)

(script-fu-register
   "FU-mycutout"
   "<Image>/Script-Fu/Artist/My Cutout"
   "Some blurb of your choosing..."
   ""
   ""
   ""
   "RGB*"
   SF-IMAGE      "Image"                     0
   SF-DRAWABLE   "Drawable"                0
   SF-ADJUSTMENT "Brightness"                  '(35 -127 127 1 10 0 0)
   SF-ADJUSTMENT "Contrast"                  '(40 -127 127 1 10 0 0)
   SF-ADJUSTMENT "Colours"                  '(32 4 32 1 10 0 0)
   SF-ADJUSTMENT "Smoothness"              '(1 1 20 1 1 0 0)
)


As to why you couldn't get it to work from the command line, the only thing I notice is that "*jpg" should be "*.jpg".
[BTW the fact that it says "Batch command completed successfully" does not mean that any images were actually processed ..it just means that the batch process completed without encountering any script interpretation or other processing errors! So if the file-glob does not match any actual files, it will show that message even though no images were actually processed.]

You should be able to invoke Gimp from any directory (just by typing "gimp") and G'MIC should load okay without DLL errors. The fact that you are getting these errors suggests that your Gimp installation is not entirely happy and I think you should try re-installing.


Last edited by jontait2 on Fri Aug 07, 2015 3:26 am, edited 4 times in total.

Top
 Post subject: Re: Unable to do simple batch process from cmd
PostPosted: Thu Aug 06, 2015 2:40 pm  (#3) 
Online
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4734
The syntax you are using is for Unix. AFAIK in Windows command prompts the only valid parameter quote is the double quote. If Scheme insists that strings should be double-quoted, then you'll have to escape the ones that bracket your file name.

_________________
Image


Top
 Post subject: Re: Unable to do simple batch process from cmd
PostPosted: Sat Aug 08, 2015 2:04 pm  (#4) 
Offline
New Member

Joined: Aug 06, 2015
Posts: 3
Thanks guys your input has been greatly helpful in debugging my script.
Changing cutout to mycutout has effectively added it to BIMP's menu so I've been batch processing my files this way.
I'm still trying to get the other codes to work if only to widen my understanding of Scheme (though learning Python would probably be the best move, need to get to that).

With the "middle-man" file, the image/drawable's ID are invalid and the error message suggests the script is working on a layer that doesn't exist anymore. Weird since my function definition is the same as other script such as cutout that don't get this error. I guess I'll give that one up.

As for the console, using the right Windows syntax (and slashes around string parameter) has made the script readable, however I get an error with the gimp-image-insert-layer function which only accepts gray types and not RGB. I make no direct call to the function so my guess is another one calls for it such as gimp-image-get-active-layer; however, the GIMP Library Reference Manual only shows the functions' return type and parameters so I'm at lost as to where the bug lies.


Top
 Post subject: Re: Unable to do simple batch process from cmd
PostPosted: Sat Aug 08, 2015 3:59 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
Hmm..
I think your problem both with the middle-man script and the command-line invocation is the RUN-NONINTERACTIVE parameter. This is erroneous and should not be present when one Script-Fu invokes another Script-Fu script or when the script is invoked from command-line batch-mode, even though it is shown that way in the Script-Fu Console.
The form should be:
(FU-cutout image drawable colours smoothness TRUE)

Basically the SFC is too stupid to realise that the procedure in question is another Script-Fu script and will therefore be loaded into the same Scheme environment and will be invoked directly (like a local subroutine) rather than via the PDB.
The run-mode parameter only applies to plugins invoked from Script-Fu scripts.
So:
(gimp-file-load ...) is an invocation of the file-load plugin and does require the run-mode parameter;
but
(FU-cutout ...) is an invocation of another Script-Fu script and does not take the run-mode parameter.

I initially made the same mistake, just copying the line verbatim from the Script-Fu Console without actually testing it and had to modify my post above later when I realised the error ..so if you took a copy of the code before my last edit, that could very well be the problem. The middle-man script as now posted above does work - I have tested it!
Same applies with your hmd-batch-stylize script ..if you remove the RUN-NONINTERACTIVE from the (Fu-cutout ..) I think you will find that it does work.


Top
 Post subject: Re: Unable to do simple batch process from cmd
PostPosted: Sun Aug 09, 2015 3:14 pm  (#6) 
Online
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4734
softunknown wrote:
however I get an error with the gimp-image-insert-layer function which only accepts gray types and not RGB. I make no direct call to the function so my guess is another one calls for it such as gimp-image-get-active-layer; however, the GIMP Library Reference Manual only shows the functions' return type and parameters so I'm at lost as to where the bug lies.


gimp-image-insert-layer want a layer of the same type as the image to which you add it. If the image is indexed, you have to create it indexed(*).

(*) IMHO this is a flaw in the API, since you provide the image in the call that creates the layer, that call could determine by itself the type of layer required.

_________________
Image


Top
 Post subject: Re: Unable to do simple batch process from cmd
PostPosted: Tue Aug 11, 2015 5:17 pm  (#7) 
Offline
New Member

Joined: Aug 06, 2015
Posts: 3
Ah I see, that did the trick! Weird there's no mention of the RUN-NONINTERACTIVE parameter being unnecessary between scripts.

Also ofnuts, I don't know if the function manages to do see if an image is indexed or not but fixing the above problem remove this error somehow


Top
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Unable to get simple python plugin to show up

8

No new posts G'MIC 3.0: A 3rd dose to process your images! (2 Years of G'MIC Dev.)

8

No new posts Attachment(s) Using Custom Font Tools as part of the Animation Process

14

No new posts Attachment(s) Unable to save preferences

2

No new posts Attachment(s) Unable to create a new template

4



* Login  



Powered by phpBB3 © phpBB Group