Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gimp Python script file load question
#9
(03-19-2021, 08:18 AM)Ofnuts Wrote:
  • Your code doesn't define a run function but a open_add_flatten_export() one.
  • I don't know how numeric arguments (your X, Y positions) are passed, you may receive them as string and have to explicitly convert them to int before using them.
  • Not convinced that your copy/paste is going to work as it is, you are using plenty of calls that I have never used and they likely don't do what you think. The best way to copy a layer between the two images is to do a layer_copy = pdb.gimp_layer_new_from_drawable(fileImage.active_layer, image), and then do  pdb.gimp_image_add_layer(image, layer_copy,1)

Great advice from Ofnuts. It simplified my code (which I tested in the UI minus the file operation and it works great). My failure is either occuring because of how I try to open the XCF, or how I'm passing command line args. The command line seems to think it's getting 1 argument even though all 5 are listed. I tried other syntaxes, like comma delimited, semi-colon delimited, etc. Can you guys think of anything else to try?

Command line output:
Code:
Traceback (most recent call last):
 File "/Applications/GIMP-2.10.app/Contents/Resources/lib/gimp/2.0/python/gimpfu.py", line 827, in _run
   return apply(func, params[1:])
 File "/Applications/GIMP-2.10.app/Contents/Resources/lib/gimp/2.0/plug-ins/python-eval.py", line 25, in code_eval
   exec code in globals()
 File "<string>", line 1, in <module>
TypeError: open_add_flatten_export() takes exactly 5 arguments (1 given)
batch command experienced an execution error
GIMP-Error: Failed to save data:


Command line arguments:
Code:
gimp -idf --batch-interpreter python-fu-eval -b 'import sys;sys.path=["."]+sys.path;import OAFE;OAFE.open_add_flatten_export("/Users/TimB/Desktop/xcftemplate.xcf" "/Users/TimB/Desktop/jpg_to_add.jpg" "2060" "410" "/Users/TimB/desktop")' -b 'pdb.gimp_quit(1)'


Plugin without definition, which I'm not using here. Filename is OAFE.py
Code:
#!/usr/bin/env python

import os, sys
from gimpfu import *

def open_add_flatten_export(infileXCF, infileJPG, x_offset, y_offset, outputFolder):
   
   # Open XCF template
   image = pdb.gimp_xcf_load(infileXCF, infileXCF)
   drawable = pdb.gimp_image_get_active_layer(image)

   # Load new JPG, and copy its contents into "layer_copy"
   fileImage = None
   fileImage = pdb.file_jpeg_load(infileJPG, infileJPG)
   layer_copy = pdb.gimp_layer_new_from_drawable(fileImage.active_layer, image)
           
   # Add layer_copy to XCF template, move it to desired position, and flatten
   pdb.gimp_image_add_layer(image, layer_copy, 1)
   pdb.gimp_layer_set_offsets(layer_copy, x_offset, y_offset)
   pdb.gimp_image_flatten(image)

   # Export JPG of flattened image
   layer = pdb.gimp_image_get_active_layer(image)
   pdb.file_jpeg_save(image, layer, outputFolder + "/" + "Export.jpg", "raw_filename", 0.9, 0, 0, 0, "Creating with GIMP", 0, 0, 0, 0)
Reply


Messages In This Thread
RE: Gimp Python script file load question - by TimorousMe - 03-19-2021, 06:48 PM

Forum Jump: