interactive batch processing

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

interactive batch processing

Gary Aitken-2
In the past I have interactively batch processed images via a shell script
that invokes gimp for each image.  This is both inconvenient and slow.
Inconvenient because there are parameters I need to enter into some python-fu
scripts that are the same for each of the images, and slow because of the
gimp startup and shutdown each time.

Is there a way to do one of the following:

A. Start gimp with a list of file names to process, and have it load only
    the first on the list.  Then when one quits or closes the image, load
    the next one, etc?

B. I can feed the list of file names to a python-fu script, which then can
    open and display the image.  Is there a way for a python-fu script to
    wait for, or be notified of, the closing of an image display?  This
    would allow the script to effectively pause and allow processing before
    opening each successive image.  gimp-context-push/pop seem like they
    may somehow enable this but it's not clear to me how they are used.

It seems like gimp-display-get-window-handle might be useful somehow, if
there were a means to be notified when the window is destroyed.

Any thoughts / hints would be much appreciated.

Thanks,

Gary
_______________________________________________
gimp-user-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

Re: interactive batch processing

Bob Long
Gary Aitken wrote on 10/12/18 4:50 am:

> In the past I have interactively batch processed images via a shell
> script
> that invokes gimp for each image.  This is both inconvenient and slow.
> Inconvenient because there are parameters I need to enter into some
> python-fu
> scripts that are the same for each of the images, and slow because of the
> gimp startup and shutdown each time.
>
> Is there a way to do one of the following:
>
> A. Start gimp with a list of file names to process, and have it load only
>    the first on the list.  Then when one quits or closes the image, load
>    the next one, etc?
>
> B. I can feed the list of file names to a python-fu script, which then
> can
>    open and display the image.  Is there a way for a python-fu script to
>    wait for, or be notified of, the closing of an image display?  This
>    would allow the script to effectively pause and allow processing
> before
>    opening each successive image.  gimp-context-push/pop seem like they
>    may somehow enable this but it's not clear to me how they are used.
>
> It seems like gimp-display-get-window-handle might be useful somehow, if
> there were a means to be notified when the window is destroyed.
>
> Any thoughts / hints would be much appreciated.

Have a look at this script:

http://gimpchat.com/viewtopic.php?f=9&t=4846&p=183034&hilit=sequential_processing#p183034

Maybe that will do what you want.

--

Bob Long


>
> Thanks,
>
> Gary
_______________________________________________
gimp-user-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

Re: interactive batch processing

Akkana Peck
In reply to this post by Gary Aitken-2
Gary Aitken writes:

> In the past I have interactively batch processed images via a shell script
> that invokes gimp for each image.  This is both inconvenient and slow.
> Inconvenient because there are parameters I need to enter into some python-fu
> scripts that are the same for each of the images, and slow because of the
> gimp startup and shutdown each time.
>
> Is there a way to do one of the following:
>
> A. Start gimp with a list of file names to process, and have it load only
>    the first on the list.  Then when one quits or closes the image, load
>    the next one, etc?

I don't know of one, though I would find it useful -- when processing
a lot of images from a photo outing, for instance.

> B. I can feed the list of file names to a python-fu script, which then can
>    open and display the image.  Is there a way for a python-fu script to
>    wait for, or be notified of, the closing of an image display?  This
>    would allow the script to effectively pause and allow processing before
>    opening each successive image.  gimp-context-push/pop seem like they
>    may somehow enable this but it's not clear to me how they are used.

I don't know of a way to do that. However, you could do something like:

def wait_until_image_closed(filename):
    '''Poll GIMP's image list, return when there's no longer an
       open image connected to filename.
    '''
    while True:
        for img in gimp.image_list():
            if img.filename == cur_filename:  # or whatever test you want
                return
        time.sleep(1)

Or better yet, get the current image before starting the loop, then
loop until that image is no longer in the image list.

I know polling is slightly icky, but I've done it in several GIMP
Python plug-ins when there was no notification available.

For this task, though, I'd be tempted to use an easier approach:

Start GIMP (with no files yet).

In a shell window, cd to the directory with the files I want to
process, and do this (with whatever list of files you want):

for fil in *.jpg; do
  gimp $fil
  read x
done

The first file comes up as a GIMP window. Process it, and when
you're ready for the next image, go to the shell window and hit
return, and the next file comes up in GIMP.

It's not quite as clean since you still have to hit return for each
image, but that's still a lot easier than navigating to each new image
in the File->Open dialog.

        ...Akkana
_______________________________________________
gimp-user-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

Re: interactive batch processing

Gary Aitken-2
In reply to this post by Bob Long
On 12/9/18 4:38 PM, Bob Long wrote:
> Gary Aitken wrote on 10/12/18 4:50 am:
...

>> Is there a way to do one of the following:
>>
>> A. Start gimp with a list of file names to process, and have it
>> load only the first on the list.  Then when one quits or closes the
>> image, load the next one, etc?
>>
>> B. I can feed the list of file names to a python-fu script, which
>> then can open and display the image.  Is there a way for a
>> python-fu script to wait for, or be notified of, the closing of an
>> image display?  This would allow the script to effectively pause
>> and allow processing before opening each successive image.
>> gimp-context-push/pop seem like they may somehow enable this but
>> it's not clear to me how they are used.
...
> Have a look at this script:
>
> http://gimpchat.com/viewtopic.php?f=9&t=4846&p=183034&hilit=sequential_processing#p183034

On 12/9/18 7:06 PM, Akkana Peck wrote:
> Gary Aitken writes:
...

>> Is there a way to do one of the following:
>>
>> A. Start gimp with a list of file names to process, and have it load only
>>     the first on the list.  Then when one quits or closes the image, load
>>     the next one, etc?
>
> I don't know of one, though I would find it useful -- when processing
> a lot of images from a photo outing, for instance.
>
>> B. I can feed the list of file names to a python-fu script, which then can
>>     open and display the image.  Is there a way for a python-fu script to
>>     wait for, or be notified of, the closing of an image display?  This
>>     would allow the script to effectively pause and allow processing before
>>     opening each successive image.  gimp-context-push/pop seem like they
>>     may somehow enable this but it's not clear to me how they are used.
>
> I don't know of a way to do that. However, you could do something like:
>
> def wait_until_image_closed(filename):
>      '''Poll GIMP's image list, return when there's no longer an
>         open image connected to filename.
>      '''
>      while True:
>          for img in gimp.image_list():
>              if img.filename == cur_filename:  # or whatever test you want
>                  return
>          time.sleep(1)
>
> Or better yet, get the current image before starting the loop, then
> loop until that image is no longer in the image list.
>
> I know polling is slightly icky, but I've done it in several GIMP
> Python plug-ins when there was no notification available.
>
> For this task, though, I'd be tempted to use an easier approach:
>
> Start GIMP (with no files yet).
>
> In a shell window, cd to the directory with the files I want to
> process, and do this (with whatever list of files you want):
>
> for fil in *.jpg; do
>    gimp $fil
>    read x
> done
>
> The first file comes up as a GIMP window. Process it, and when
> you're ready for the next image, go to the shell window and hit
> return, and the next file comes up in GIMP.
>
> It's not quite as clean since you still have to hit return for each
> image, but that's still a lot easier than navigating to each new image
> in the File->Open dialog.

Thanks both of you for your suggestions and pointers.  I think all of
those will enable me to work out a solution.

Thanks again.

Gary
_______________________________________________
gimp-user-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list
Reply | Threaded
Open this post in threaded view
|

Re: interactive batch processing

Ofnuts-2
In reply to this post by Gary Aitken-2
On 12/9/18 7:50 PM, Gary Aitken wrote:

> In the past I have interactively batch processed images via a shell
> script
> that invokes gimp for each image.  This is both inconvenient and slow.
> Inconvenient because there are parameters I need to enter into some
> python-fu
> scripts that are the same for each of the images, and slow because of the
> gimp startup and shutdown each time.
>
> Is there a way to do one of the following:
>
> A. Start gimp with a list of file names to process, and have it load only
>    the first on the list.  Then when one quits or closes the image, load
>    the next one, etc?
>
> B. I can feed the list of file names to a python-fu script, which then
> can
>    open and display the image.  Is there a way for a python-fu script to
>    wait for, or be notified of, the closing of an image display? This
>    would allow the script to effectively pause and allow processing
> before
>    opening each successive image.  gimp-context-push/pop seem like they
>    may somehow enable this but it's not clear to me how they are used.
>
> It seems like gimp-display-get-window-handle might be useful somehow, if
> there were a means to be notified when the window is destroyed.


A) my own ofn-file-next  script may help if the files are in some
recognizable numerical sequence (IMG_678.JPG, IMG_679.JPG,
IMG_690.JPG)(some holes in the sequence are allowed). You can assign it
to some keyboard shortcut and it will export/close the current image,
and load the next in the sequence. Typically you start Gimp, usin
File>Ope, to open the first file in th eseqquence, and hit the shortcut
to advance to the next file. Available here:
<http://sourceforge.net/projects/gimp-tools/files/scripts/>.

This, combined with the "Repeat last filter" (Ctrl-F) (at the top of the
"Filters" menu, repeats the last filter on the current image with the
same parameters), should make you process your image sequence rather
quickly (two keystrokes per image).

B) You can write a script that reads a list of files (or lists files in
a directory), and loads each file, applies a filter, and saves the
result. But you don't really change the behavior of the initial script.
gimp_context_{push|pop} have nothing to do with this, they are used to
save/restore the paint context (FG/BG colors, gradient, brush... etc).
An example here:
<https://stackoverflow.com/questions/44430081/how-to-run-python-scripts-using-gimpfu-from-windows-command-line/44435560#44435560>


There is also a "BIMP" Gimp plugin (the B is for "Batch") that is
supposed to be able to run Gimp commands over a series of files. I don't
know how well it supports a random filter.





_______________________________________________
gimp-user-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list
List archives:   https://mail.gnome.org/archives/gimp-user-list