(12-30-2021, 04:56 PM)z-uo Wrote: To transform the layer to a tensor or numpy or any other standard python information I decide to store it as PNG and after some computation I will load it, but the load functions seams not towork:
It gets a gimp error that says that I try to add a layer to an incorrect image (it seems because img is different from image). I attached the full example code.Code:
save_image(image, drawable, os.path.join(base_dir, "cache.png"))
img = load_image(os.path.join(base_dir, "cache.png"))
layer = Gimp.Layer.new(
img, 'loaded',
drawable.get_width(), drawable.get_height(),
Gimp.ImageType.RGBA_IMAGE, 100.0,
Gimp.LayerMode.NORMAL
)
position = Gimp.get_pdb().run_procedure('gimp-image-get-item-position',
[image,
drawable]).index(1)
image.insert_layer(layer,None,position)
How do I load a png as a layer correctly?
I find the response here:
Code:
img = load_image(os.path.join(base_dir, "cache.png"))
result_layer = img.get_active_layer()
layer = Gimp.Layer.new_from_drawable(result_layer, image)
layer.set_name("loaded")
(12-30-2021, 05:53 PM)programmer_ceds Wrote: Try function gimp_file_load_layer() or gimp_file_load_layers() - see the PDB
Maybe that is a better solution than mine! Thank you!