Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gimp 2.10 'with files' batch
#1
As you know, I am not a coder. 
Selina in this post https://www.gimp-forum.net/Thread-Changi...5#pid11445 has an unknown number of .xcf files of various ppi and would like all as 96 ppi.

A little plugin to do one at a time: Does not do much, sets the ppi and saves the image straight away.

Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

from gimpfu import*

def plugin_96ppi(img, drawable):
    
    filename = img.filename
    pdb.gimp_image_set_resolution(img, 96.0, 96.0)
    pdb.gimp_file_save(img, drawable, filename, filename)    
    pdb.gimp_image_clean_all(img)

register(
        "python_fu_96ppi",
        "set96ppi",
        "*",
        "*",
        "*",
        "2018",
        "<Image>/Tools/set-96ppi",
        "*",
        [],
        [],
        plugin_96ppi)

main()

Can this be used in a Gimp batch mode? https://wiki.gimp.org/wiki/Release:2.10_changelog has a with-files macro. Seems simple but I can not get this to work. Not using the flatpak, using a 'bunt' 18.10 VM & Gimp 2.10.6

Quote:-A new 'with-files' macro is available to run commands on several files at once. For instance, if you want to invert colors of all png files in a directory, and save them as jpg, you could run:
gimp -i -b '(with-files "*.png" (gimp-invert layer) \
             (gimp-file-save 1 image layer \
             (string-append basename ".jpg") \
             (string-append basename ".jpg") ))'
             
**quiet rant** Gimp really needs some sort of macro facility that does not rely on command line or writing a script. Tried all ways with BIMP but it just does not handle .xcf files with several layers.
Reply
#2
You don't need "with_files" in Python since you have something like this already in the language:

Code:
import glob

for file in glob.glob(sourcedir+'/*.xcf'):  # '/' also works in Windows
   img=pdb.gimp_file_load(file)
   pdb.gimp_image_set_resolution(img, 96.0, 96.0)
   pdb.gimp_file_save(img, drawable, file, file)    
   pdb.gimp_image_clean_all(img)
   pdb.gimp_image_delete(image) # only removes the image from Gimp!

You stuff this a plugin that takes a single argument that you declare as a PF_DIRNAME in the registration. The user starts the script from a Gimp menu; enters the directory, and there you go.

Coded "from the hip", so some mistakes/oversight possible.

You can make that a shell batch but it's a bit more complicated.
Reply


Forum Jump: