It is currently Fri Apr 26, 2024 6:17 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 20 posts ] 
Author Message
 Post subject: Export image using command line in windows
PostPosted: Fri Oct 09, 2015 2:34 am  (#1) 
Offline
New Member

Joined: Oct 09, 2015
Posts: 4
Hi I want to export all the images from a folder in one go on a windows machine.

I am trying to use the "file-jpeg-save" from command line but getting error stating batch command experienced an execution error.

The command I am executing on windows command line is

set gimp="c:\Program Files\GIMP 2\bin\gimp-console-2.8.exe"

for %i in (*.jpg) do %gimp% -b "(file-jpeg-save 0 %i drawable %i %i 90 0 1 1 comment 4:4:4 1 0)"

Can anybody help me to undestand the issue.

Thanks in advance


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: Export image using command line in windows
PostPosted: Fri Oct 09, 2015 10:35 am  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
You can only export something you have loaded first.

But if what you want to do is change some characteristics of a JPEG file, you should look into the "convert" command from the ImageMagick toolbox.

_________________
Image


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Fri Oct 09, 2015 10:53 am  (#3) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
jhingranamit wrote:
I am trying to use the "file-jpeg-save" from command line but getting error stating batch command experienced an execution error.

The code passed on the command line -- in your case, file-jpeg-save -- needs to be valid Script-fu, just as used within scripts. This means that second argument needs to be the image ID of an opened image, not the name of the file on disk. Your code needs to load the file as an image and then determine the layer ID of the image's layer before you can save the file as a JPEG.

Also, your command is looping through, opening GIMP for a file and then closing GIMP only to have to re-open GIMP for the next file. It is far better to just open GIMP once and then perform the looping within you script code.

I have written a macro that simplifies this process somewhat, and can be downloaded from HERE. Save it to a file in your GIMP scripts folder and then code such as the following should work. (Warning: this command will overwrite the original JPEG files.)
%gimp% -i -f -b "(with-files \"*.jpg\"
                    (file-jpeg-save RUN-NONINTERACTIVE
                                    image
                                    layer
                                    filename
                                    filename
                                    90 ; jpg compression
                                    0 ; smoothing
                                    1 ; optimize
                                    1 ; progressive
                                    \"\" ; comment
                                    0 ; subsmp (0-4)
                                    1 ; baseline
                                    0 ; restart
                                    0 ;dct
                                    ))"

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Fri Oct 09, 2015 11:03 am  (#4) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2424
Quote:
file-jpeg-save 0 %i drawable %i %i 90 0 1 1 comment 4:4:4 1 0


Not quite sure what that is intended to do, but for a GUI you could try the BIMP plugin http://www.alessandrofrancesconi.it/projects/bimp/

Here changing the jpeg compression, subsampling and adding a comment

Attachment:
usingbimp.jpg
usingbimp.jpg [ 60.74 KiB | Viewed 8176 times ]

_________________
Image


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Mon Oct 12, 2015 4:06 am  (#5) 
Offline
New Member

Joined: Oct 09, 2015
Posts: 4
@saulgoode

Thanks for your reply. I have copied the macro to script folder. But, the command is still throwing error for me. I am just a toddler with the tool, can you please give me a command that I can copy/paste & it works for me.

The current command(s) I tried are

1.
set gimp="c:\Program Files\GIMP 2\bin\gimp-console-2.8.exe"

%gimp% -i -f -b "(with-files \"*.jpg\" (file-jpeg-save 0 \"C:\\temp\\1.jpg\" drawable \"C:\\temp\\1.jpg\" 90 0 1 1 \"\" 0 1 0 0 ))"

2.
set gimp="c:\Program Files\GIMP 2\bin\gimp-console-2.8.exe"

%gimp% -i -f -b "(with-files \"*.jpg\" (file-jpeg-save 0 -i drawable -i 90 0 1 1 \"\" 0 1 0 0 ))"


Thanks a lot, plz help


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Mon Oct 12, 2015 4:57 am  (#6) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
I do not use Windows or have it available for testing, but I believe that the command I previously posted should work.

set gimp="c:\Program Files\GIMP 2\bin\gimp-console-2.8.exe"
%gimp% -i -f -b "(with-files \"*.jpg\" (file-jpeg-save 1 image layer filename filename 90 0 1 1 \"\" 0 1 0 0 ))"


If you leave out the -i switch then you will be able to see whether GIMP actually opens and the status bar shows the processing of each of the files. The -f switch can also be left out but then GIMP will take some extra time to load your fonts (which aren't ever used).

Note that image, layer, and filename are the literal words -- you should not substitute anything else in their place (the macro takes care of this).

EDIT: Changed run-mode to NONINTERACTIVE per correction suggested by paynekj.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Last edited by saulgoode on Mon Oct 12, 2015 9:56 am, edited 2 times in total.

Top
 Post subject: Re: Export image using command line in windows
PostPosted: Mon Oct 12, 2015 5:33 am  (#7) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
saulgoode wrote:
I do not use Windows or have it available for testing, but I believe that the command I previously posted should work.

set gimp="c:\Program Files\GIMP 2\bin\gimp-console-2.8.exe"
%gimp% -i -f -b "(with-files \"*.jpg\" (file-jpeg-save 0 image layer filename filename 90 0 1 1 \"\" 0 1 0 0 ))"



It's working for me on a Windows 7 machine, although I am puzzled why you set the run-mode of flie-jpeg-save to RUN_INTERACTIVE as, despite the -i flag, I get the save-options dialog appearing for each file!

Attachment:
Untitled.png
Untitled.png [ 34.94 KiB | Viewed 8084 times ]


Kevin

Things to be careful of.
The path to the gimp executable must be correct.
Don't put any spaces round the equals in the set command:
  set gimp = "C:\Program Files\Program Files\GIMP-2.8.14\bin\gimp-console-2.8.exe"
WILL NOT WORK


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Mon Oct 12, 2015 6:50 am  (#8) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2247
Location: Poland
Wearing Why complicate life.
Rich2005 gave a simple and effective solution :yes
Why are you ignored?

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Mon Oct 12, 2015 8:18 am  (#9) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2424
Because it is like doing a crossword, it is a challenge with great satisfaction when you get it to work. :jumpclap

plus to be honest, command line was in the subject ;)

_________________
Image


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Mon Oct 12, 2015 11:23 am  (#10) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
paynekj wrote:
... although I am puzzled why you set the run-mode of flie-jpeg-save to RUN_INTERACTIVE as, despite the -i flag, I get the save-options dialog appearing for each file!

Copy and paste error on my part. I almost never use numeric values in place of enumerated constants -- it is much easier to read the code and spot errors when things are spelled out.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Tue Oct 13, 2015 3:49 am  (#11) 
Offline
New Member

Joined: Oct 09, 2015
Posts: 4
@paynekj

I have removed the intractive tag the cmmand is getting executed but I am still getting a error msg, screen-shot attached

Please advice.Image


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Tue Oct 13, 2015 6:08 am  (#12) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2247
Location: Poland
Solutions are many - for you should be using the simplest solution BIMP (rich2005) - why the command line is to be a better solution?

Why are you interested in only the command line - why that is?

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Tue Oct 13, 2015 6:37 am  (#13) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
jhingranamit wrote:
I have removed the intractive tag the cmmand is getting executed but I am still getting a error msg, screen-shot attached

Please advice.


Oops. The jpeg compression level needs to be normalized. Change it from 90 to 0.9 .

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Wed Oct 14, 2015 2:07 am  (#14) 
Offline
New Member

Joined: Oct 09, 2015
Posts: 4
@saulgoode

Changed the argument to .9 as suggested, still getting error :(
Anyone please help me to pull this one off, I am really sorry I am posting every day with a new issue, but can't help it I have just started using the tool & you guys are the best help for me, appreciate your quick replies.

Please suggest


Image


Thanks


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Wed Oct 14, 2015 9:46 am  (#15) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Well, the error now appears to be caused by some file called "bimp-locale". To my knowledge, this has nothing to do with my macro and is not part of bog standard GIMP.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Wed Oct 14, 2015 10:09 am  (#16) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
I think you will find that the errors have nothing to do with the batch process.

If you check your files, you should see that they have changed.

Kevin


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Wed Oct 14, 2015 10:54 am  (#17) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
The error message about "bimp-locale" is just a red-herring - that file is actually a folder containing locale-specific settings for the BIMP plugin, but GIMP is too stupid to realize that it's not an executable file and so tries to actually load and execute the folder, and inevitably fails. So you can safely ignore that error message - that will probably always happen but you don't normally notice it. [The same thing happens with any other folders or non-executable files included in the plug-ins folder, but you only see the error message if you start GIMP from a console!]

As Kevin said, the batch process probably is actually running, so check to see if your .jpg files have actually been processed.
But you should terminate the batch run properly with:
-b "(gimp-quit 0)"

Ref: http://www.gimp.org/tutorials/Basic_Batch

So try:
set gimp="c:\Program Files\GIMP 2\bin\gimp-console-2.8.exe"
%gimp% -i -f -b "(with-files \"*.jpg\" (file-jpeg-save 1 image layer filename filename 0.9 0 1 1 \"\" 0 1 0 0 ))" -b (gimp-quit 0)"


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Wed Oct 14, 2015 1:51 pm  (#18) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
jontait2 wrote:
But you should terminate the batch run properly with:
-b "(gimp-quit 0)"

Actually, the gimp-quit is already included at the end of the with-files macro:
(define-macro (with-files pattern . body)
  (let ((loop (gensym))
        (filenames (gensym)))
    `(begin
       (let ,loop ((,filenames (cadr (file-glob ,pattern 1))))
         (unless (null? ,filenames)
           (let* ((filename (car ,filenames))
                  (image (catch #f (car (gimp-file-load RUN-NONINTERACTIVE
                                                        filename
                                                        filename ))))
                  (layer (if image (car (gimp-image-get-active-layer image)) #f))
                  (basename (catch filename
               (unbreakupstr (butlast (strbreakup filename ".")) "."))))
             (when image
               ,@body
               (gimp-image-delete image)))
           (,loop (cdr ,filenames))))
       (gimp-quit 0))))

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Wed Oct 14, 2015 2:26 pm  (#19) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
saulgoode wrote:
jontait2 wrote:
But you should terminate the batch run properly with:
-b "(gimp-quit 0)"

Actually, the gimp-quit is already included at the end of the with-files macro:
(define-macro (with-files pattern . body)
  (let ((loop (gensym))
        (filenames (gensym)))
    `(begin
       (let ,loop ((,filenames (cadr (file-glob ,pattern 1))))
         (unless (null? ,filenames)
           (let* ((filename (car ,filenames))
                  (image (catch #f (car (gimp-file-load RUN-NONINTERACTIVE
                                                        filename
                                                        filename ))))
                  (layer (if image (car (gimp-image-get-active-layer image)) #f))
                  (basename (catch filename
               (unbreakupstr (butlast (strbreakup filename ".")) "."))))
             (when image
               ,@body
               (gimp-image-delete image)))
           (,loop (cdr ,filenames))))
       (gimp-quit 0))))

Ah!


Top
 Post subject: Re: Export image using command line in windows
PostPosted: Thu Oct 15, 2015 2:52 pm  (#20) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
@Saul
A minor point: using the usual command-line batch syntax -b '(...)' -b '(gimp-quit 0)'
produces the message: "batch command executed successfully" on completion of the first -b '(...)'
[There is no message from the second -b because that batch run never actually finishes - the GIMP core terminates itself when it gets the quit command, and the host OS then kills the child processes, including the script-fu plugin. So the Script-Fu engine never actually completes execution of the script and never outputs the second completion message.]

Ergo, including the (gimp-quit ) in your (with-files ) macro means that there is no completion message output at all.
Perhaps you could output a bespoke completion message eg. of the form "macro with-files completed, N files processed, quitting GIMP..."


Top
Post new topic Reply to topic  [ 20 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Calling GIMP Plug-in From Command Line - on Windows

0

No new posts How do you run GIMP from the command line?

1

No new posts Attachment(s) G'MIC> Pattern> Strip command line?

2

No new posts GEGL command line and layer modes?

2

No new posts Attachment(s) export an image

4



* Login  



Powered by phpBB3 © phpBB Group