03-18-2021, 05:09 PM
(This post was last modified: 03-18-2021, 05:38 PM by TimorousMe.)
Hi Kevin. Yes that is me. My latest plugin is shown below. Everything works in the GIMP UI, but when I add my call for pdb.gimp_xcf_load(0, infileA, infileA) and introduce infileA into the definition and parameters, it fails.
I think there may be a problem because the image object isn't explicitly linked to my XCF or JPG. It would be great to avoid a file wrapper for opening the XCF, but if I need to I understand.
Below is my command line calls (two options I tried) and my plugin. These are the errors I get when I use these command line calls:
First command line call: "Error: eval: unbound variable: open_add_flatten_export"
Second command line call:
GIMP-Error: Failed to save data:
You have a writable data folder configured (/Users/TBradley/Library/Application Support/GIMP/2.10/gradients), but this folder does not exist. Please create the folder or fix your configuration in the Preferences dialog's 'Folders' section.
/Applications/GIMP-2.10.app/Contents/MacOS/gimp: GEGL-WARNING: (../../../../gtk/source/gegl-0.4.26/gegl/buffer/gegl-tile-handler-cache.c:1076):gegl_tile_cache_destroy: runtime check failed: (g_queue_is_empty (&cache_queue))
EEEEeEeek! 9 GeglBuffers leaked
To debug GeglBuffer leaks, set the environment variable GEGL_DEBUG to "buffer-alloc"
Here's my plugin:
I think there may be a problem because the image object isn't explicitly linked to my XCF or JPG. It would be great to avoid a file wrapper for opening the XCF, but if I need to I understand.
Below is my command line calls (two options I tried) and my plugin. These are the errors I get when I use these command line calls:
First command line call: "Error: eval: unbound variable: open_add_flatten_export"
Second command line call:
GIMP-Error: Failed to save data:
You have a writable data folder configured (/Users/TBradley/Library/Application Support/GIMP/2.10/gradients), but this folder does not exist. Please create the folder or fix your configuration in the Preferences dialog's 'Folders' section.
/Applications/GIMP-2.10.app/Contents/MacOS/gimp: GEGL-WARNING: (../../../../gtk/source/gegl-0.4.26/gegl/buffer/gegl-tile-handler-cache.c:1076):gegl_tile_cache_destroy: runtime check failed: (g_queue_is_empty (&cache_queue))
EEEEeEeek! 9 GeglBuffers leaked
To debug GeglBuffer leaks, set the environment variable GEGL_DEBUG to "buffer-alloc"
Quote:First command line call:
gimp -i -b '(open_add_flatten_export "/Users/TimB/Desktop/xcf_template.xcf" "/Users/TimB/Desktop/jpg_to_add.jpg" "2060" "410" "/Users/TimB/Desktop")' -b '(gimp-quit 0)'
Second command line call:
gimp -i --batch-interpreter python-fu-eval -b pdb.python_fu_open_add_flatten_export "/Users/TimB/Desktop/xcf_template.xcf" "/Users/TimB/Desktop/jpg_to_add.jpg" "2060" "410" "/Users/TimB/desktop" -b 'pdb.gimp_quit(0)'
Here's my plugin:
Code:
#!/usr/bin/env python
from gimpfu import *
def open_add_flatten_export(image, layer, infileA, infileB, x_offset, y_offset, outputFolder):
# Open XCF template
pdb.gimp_xcf_load(0, infileA, infileA)
try:
# Open file.
fileImage = None
if(infileB.lower().endswith(('.jpeg', '.jpg'))):
fileImage = pdb.file_jpeg_load(infileB, infileB)
# Create new layer.
newLayer = gimp.Layer(image, "New Layer Name", layer.width, layer.height, layer.type, layer.opacity, layer.mode)
# the +1 adds it behind the top layer
image.add_layer(newLayer, +1)
# Put image into the new layer.
fileLayer = fileImage.layers[0]
pdb.gimp_edit_copy(fileLayer)
floating = pdb.gimp_edit_paste(newLayer, True)
# Update the new layer.
newLayer.flush()
newLayer.merge_shadow(True)
newLayer.update(0, 0, newLayer.width, newLayer.height)
# Flatten + offset floating layer, then flatten image
pdb.gimp_floating_sel_to_layer(floating)
pdb.gimp_layer_set_offsets(floating, 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)
else:
gimp.message("The image could not be opened since it is not an image file.")
except Exception as err:
gimp.message("Unexpected error: " + str(err))
register(
"python_fu_open_add_flatten_export",
"Open XCF, add image to layer, flatten, and export",
"Open XCF, add image to layer, flatten, and export",
"Tim B.",
"Tim B.",
"2021",
"<Image>/Filters/Tim/Open, add, flatten, export",
"*",
[
(PF_FILE, "infileA", "XCF template", ""),
(PF_FILE, "infileB", "JPG to add", ""),
(PF_INT, "x_offset", "X offset", ""),
(PF_INT, "y_offset", "Y offset", ""),
(PF_DIRNAME, "outputFolder", "Output directory", ""),
],
[],
open_add_flatten_export)
main()