Gimp-Forum.net
Learn to create Python3 plugins - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: Learn to create Python3 plugins (/Thread-Learn-to-create-Python3-plugins)

Pages: 1 2


RE: Learn to create Python3 plugins - z-uo - 12-30-2021

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?


RE: Learn to create Python3 plugins - programmer_ceds - 12-30-2021

Try function gimp_file_load_layer() or gimp_file_load_layers() - see the PDB


RE: Learn to create Python3 plugins - z-uo - 12-30-2021

(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!


RE: Learn to create Python3 plugins - z-uo - 12-31-2021

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!


RE: Learn to create Python3 plugins - z-uo - 01-02-2022

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.