Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Learn to create Python3 plugins
#11
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:
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)
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.
How do I load a png as a layer correctly?


Attached Files
.txt   save_and_load.txt (Size: 6.94 KB / Downloads: 224)
Reply
#12
Try function gimp_file_load_layer() or gimp_file_load_layers() - see the PDB
Reply
#13
(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:
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)
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.
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!
Reply
#14
I write my first Deep Learning plugin for Gimp! It use the Real-ERSGAN [Xintao 2021], the GIMP plugin can be founded here.
For now It have no settings into GUI, no waiting spinner and no recommendation about the usage on CPU that can be very slowly, But it work! Now I must study and improve my abilities! Maybe I will try to create also automation test...
Thanks for all!
Reply
#15
I try to use Glade and it seams work correctly, But I do not Understand why it expand automatically on the width but not on the height:
Code:
GimpUi.init("add_balloon.py")
dialog = GimpUi.Dialog(use_header_bar=True,
                                   title=_("Add Balloon"),
                                   role="add-balloon-Python3")
dialog.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
dialog.add_button(_("_OK"), Gtk.ResponseType.OK)

builder = Gtk.Builder()
dir_path = os.path.dirname(os.path.realpath(__file__))
builder.add_from_file(os.path.join(dir_path, "ui_nodialog.glade"))

box = builder.get_object("box")
dialog.get_content_area().add(box)
box.show()

How can I specify on GimpUi.Dialog to expand in all dimensions automatically when the user resizes the window?

Full code are available here.
Reply


Forum Jump: