Post Reply 

How to open image as new layer with gimpfu?

Feb 23, 2014, 03:34
Post: #1
How to open image as new layer with gimpfu?
I'm just starting out with the Python gimpfu module, experimenting with the Python-Fu interpreter, which seems like the best way to learn how it works. I'm finding the object model very counter-intuitive, though.

What I want to do is simply to load a set of PNG images on disk (same size and type) into a single GIMP image as layers for additional processing.

In the GUI, I would use "File>Open as Layers..." for this.

In the Python-Fu intepreter, I keep hitting roadblocks, though.

There is a function to load the file:

pdb.file_png_load(...)

But it creates a new GIMP image stack for each one. Every method I've attempted to extract the layer with the image data and put into the first image has failed, usually with a complaint about how the layer should only be used with its source image.

What is GIMP actually doing when I use the "File>Open as Layers..." tool -- and how would you express that in Python-Fu?

Thanks!
Find all posts by this user
Quote this message in a reply
Feb 23, 2014, 06:30
Post: #2
RE: How to open image as new layer with gimpfu?
(Feb 23, 2014 03:34)Digitante Wrote:  I'm just starting out with the Python gimpfu module, experimenting with the Python-Fu interpreter, which seems like the best way to learn how it works. I'm finding the object model very counter-intuitive, though.

What I want to do is simply to load a set of PNG images on disk (same size and type) into a single GIMP image as layers for additional processing.

In the GUI, I would use "File>Open as Layers..." for this.

In the Python-Fu intepreter, I keep hitting roadblocks, though.

There is a function to load the file:

pdb.file_png_load(...)

But it creates a new GIMP image stack for each one. Every method I've attempted to extract the layer with the image data and put into the first image has failed, usually with a complaint about how the layer should only be used with its source image.

What is GIMP actually doing when I use the "File>Open as Layers..." tool -- and how would you express that in Python-Fu?

Thanks!
Hi,
This is probably not much help as I don't know python...
But after searching around, I found this
pdb.gimp_file_load_layer(image, filename)
Find all posts by this user
Quote this message in a reply
Feb 23, 2014, 08:08
Post: #3
RE: How to open image as new layer with gimpfu?
Thank you. That absolutely is helpful. I suppose I should've been able to find that, but clearly I missed it.

I did find another way, although it was clumsy. I loaded two images and then did a copy and paste using pdb.gimp_edit_copy() and pdb.gimp_edit_paste() functions.
Find all posts by this user
Quote this message in a reply
Feb 23, 2014, 09:36
Post: #4
RE: How to open image as new layer with gimpfu?
Don't use copy/paste for this. There are function to create a copy of a layer anf attach it to another image (beware that there is also an API to make a copy of a layer to use in the same image, which is not enough for this particular need).

Code:
layerCopy=pdb.gimp_layer_new_from_drawable(layerSource,targetImage)
targetImage.add_layer(layerCopy,0)

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Scale image to specific size MattRothschild 1 104 Sep 15, 2017 11:13
Last Post: ythgilb
  Script-fu: How to create new, addressable layer using gimp-floating-sel-to-layer Bertholomäus 2 146 Aug 31, 2017 14:32
Last Post: Bertholomäus
  Dividing and printing a large image RayArdia 1 101 Aug 9, 2017 07:22
Last Post: ythgilb
  Late binding / COM for opening an image into GIMP? i73 2 126 Aug 4, 2017 17:39
Last Post: i73
  PDB call to Image/Canvas size... ? Shadowes 3 382 Sep 1, 2014 22:31
Last Post: Shadowes

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS