Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
script to merge files into layers and set a layer mask
#1
Hallo,

I need a script for batch mode:

There are files t0.tif and t1.tif (single page tifs) in the current directory.

The script should open these files and put them into a single file as layers
(t0.tif as bottom and t1.tif as top layer).

Then, the script should set "grain merge" to the top layer and add a white
layer mask.

I am somewhat familiar with (scheme)lisp, but I have no knowledge on
script-fu.

Finally, the script should save the file in standard gimp format.

Daniel
Reply
#2
Hallo,

well, I should provide some motivation.    The first person who posts a working script (as below) gets exclusively a high resolution tif (3526 x 3246)  of the attached photo for private usage.  (I am the copyright holder and I have the permission to publish the photo.)

The script has to be written in python-fu, and I want to call the script from cygwin under windows 20 (64bit).

I have files t00.tif, ..., t11.tif (single page tifs) in the current directory.  The script should generate a single file with
t00.tif, ..., t11.tif as layers.    t00.tif should be the top layer, ..., t11 the bottom layer.

The above 11 layers should get a white layer mask, and the mix method should be "grain merge".

Best regards,
Daniel


Attached Files Image(s)
   
Reply
#3
I wrote this based on your first incomplete specification to give me some practice with Python-Fu, and as you've now changed to a new incomplete specification, you can regard this as a starter for you to continue with.


.zip   danieldd.zip (Size: 1.11 KB / Downloads: 293)
Reply
#4
(09-14-2020, 07:28 AM)Kevin Wrote: I wrote this based on your first incomplete specification to give me some practice with Python-Fu, and as you've now changed to a new incomplete specification, you can regard this as a starter for you to continue with.

Thank you,   I will have a look at the script late in the evening.

Daniel
Reply
#5
Hallo,

based on Kevins script I wrote the code, below.

When I copy and paste the code into Gimp's python console, it works fine. 
However, when I want to run the code outside Gimp (e.g. by double clicking
GIMP 2/bin/python.exe), it cannot import from gimpfu.




Code:
ImportError: No module named gimpfu


My script code:


Code:
import os,glob
from gimpfu import *

ctrl = 0
os.chdir('D:/z')
for tiffile in glob.glob('*tif'):
  print tiffile
  tiffile = 'D:/z/' + tiffile
  if ctrl == 0:
    image = pdb.gimp_file_load(tiffile,tiffile)
    ctrl = 1
  else:
    newlayer = pdb.gimp_file_load_layer(image, tiffile)
    image.add_layer(newlayer, -1)
    newlayer.mode = LAYER_MODE_GRAIN_MERGE
    mask_channel = newlayer.create_mask(ADD_MASK_WHITE)
    newlayer.add_mask(mask_channel)

pdb.gimp_display_new(image)
gimp.displays_flush()
Reply
#6
You can't run GIMP scripts/plug-ins outside GIMP.

For the code I wrote, I made a windows batch file (.bat) with this inside:

Code:
"C:\Program Files\GIMP 2.10\bin\gimp-console-2.10.exe" -df -b "(python-fu-danieldd RUN-NONINTERACTIVE \"P1320328_sml.JPG\" \"P1320578_sml.JPG\" \"fred.xcf\")" -b "(gimp-quit 0)"

And I've deleted your message with the link to your image because I'm not interested in having a copy of it, but thanks anyway.
Reply
#7
Hallo,

I registered the script as follows:


Code:
register(
    "WaveletImporter",    
    "WaveletImporter",
    "WaveletImporter",
    "Dr. Daniel Kirsten",
    "Dr. Daniel Kirsten",
    "September 2020",
    "WaveletImporter",
    "",
    [],  
    [],
    wavelet_importer,
    menu="<Image>/Filters/"
)


I start gimp from cygwin by


Code:
/cygdrive/c/Program\ Files/GIMP\ 2/bin/gimp-2.10.exe --batch-interpreter=python-fu-eval -b 'WaveletImporter'

The script is not executed, but I see the error message:


Code:
 File "C:\Program Files\GIMP 2\lib\gimp\2.0\python/gimpfu.py", line 827, in _run
    return apply(func, params[1:])
  File "C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins\python-eval\python-eval.py", line 25, in code_eval
    exec code in globals()
  File "<string>", line 1, in <module>
NameError: name 'WaveletImporter' is not defined


However, the script appears in the "Filters"-menu, and when I click on it, it works fine.

When I call gimp from windows, it shows the same behavior, but I do not see the error message.

Daniel
Reply
#8
Because your script as seen from Gimp is really hidden in pdb.python-fu-WaveletImporter. Under the hood this procedure starts your script as a new process that loads the .py file.

However, see:

https://stackoverflow.com/questions/4443...0#44435560
Reply
#9
Hallo,

I made numerous attempts, e.g. i I tried


Code:
/cygdrive/c/Program\ Files/GIMP\ 2/bin/gimp-2.10.exe --verbose --batch-interpreter=python-fu-eval -b 'import sys; import DK_plugins; DK_plugins.wavelet_importer() '

It seems that DK_plugins.py is indeed imported, but the script is not executed.


Daniel
Reply
#10
On the SO example, the bit sys.path=['.']+sys.path; that you didn't copy adds the current directory (which is hopefully the one with the python script) to the Python path, so that the subsequent import finds it.
Reply


Forum Jump: