It is currently Tue Jul 02, 2024 9:36 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 17 posts ] 
Author Message
 Post subject: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 1:02 am  (#1) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
This must be simple. I am simply trying to load my signature.png file to a new layer.

filename=r"signature.jpg"
layer = pdb.gimp_file_load_layer(image, filename)

and I tried:

filename=r"signature.png"
image = pdb.file_png_load(filename, filename)

and neither of them work. The new layer doesn't show up.


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 1:39 am  (#2) 
Offline
New Member

Joined: Sep 29, 2021
Posts: 4
I go to file and then open as layers and then navigate to the folder that holds the file and select the image file. Is that what you are doing?


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 1:53 am  (#3) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
ecs1749 wrote:
This must be simple. I am simply trying to load my signature.png file to a new layer.

filename=r"signature.jpg"
layer = pdb.gimp_file_load_layer(image, filename)

and I tried:

filename=r"signature.png"
image = pdb.file_png_load(filename, filename)

and neither of them work. The new layer doesn't show up.


Unless the file is in Gimp's current directory(*), there must be a complete path in the file name.

(*) If you start Gimp by clicking an icon this is very unlikely

_________________
Image


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 4:01 am  (#4) 
Offline
Global Moderator
User avatar

Joined: Apr 01, 2012
Posts: 7744
Location: On the other side of this screen
ecs1749 wrote:
This must be simple. I am simply trying to load my signature.png file to a new layer.

filename=r"signature.jpg"
layer = pdb.gimp_file_load_layer(image, filename)

and I tried:

filename=r"signature.png"
image = pdb.file_png_load(filename, filename)

and neither of them work. The new layer doesn't show up.

Dont understand what you are trying to do
Have you tried this?
Image

_________________


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 4:36 am  (#5) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2437
@ ecs1749

Keep going developing your plugin, just throwing a what-if into the hat.

Importing as a layer will plant the layer centered in the base image. That might be ok and work with your work flow. Might not be so good with diferent size images or if the sig is needed in a specific location. More code in your plugin.

For any single image an easy alternative is make your sig file into a greyscale brush. And use it as a stamp.

Attachment:
sig.jpg
sig.jpg [ 158.21 KiB | Viewed 1182 times ]


If the intention is for batch purposes, then there are already scripts to do this or use the Gimp plugin BIMP.

_________________
Image


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 10:59 am  (#6) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
Assuming this is what you need, this will create a user dialog and you can find the image using a directory option. The image is place in the center of the canvas


#!/usr/bin/env python
# -*- coding: utf-8 -*-

from gimpfu import *

def open_an_image(filename):   

    img = pdb.gimp_image_new(1920, 1080, RGB)
    imagLayer = pdb.gimp_file_load_layer(img, filename)
    pdb.gimp_image_add_layer(img, imagLayer, 0)
   
    #Center the image to the canvas
    imagLayer.set_offsets((img.width - imagLayer.width) / 2, (img.height - imagLayer.height) / 2)
   
    pdb.gimp_display_new(img)
   
register(
    "open_an_image",
    "Open any image",           #Short description
    "Open any type of image",   #Long description
    "Your name",
    "Your name",
    "2021",
    "Open my favorite image",  #This is how you want it to appear in GIMP menu
    "",
    [   
    (PF_FILENAME, "filename", "Image:", None),  #Directory option
    ],
    [],
    open_an_image, menu="<Image>/Python-Fu/Open my favorite image"), #This is how you want it to appear in GIMP menu
main()





Or you can center the image and make the image as high of the canvas

#!/usr/bin/env python     
# -*- coding: utf-8 -*-   

#Above codings
#1. Python Source Code Encodings
#2. Most popular Python Source Code Encodings (Use both)

from gimpfu import *     #This willgives you all of the constants, the procedural database (pdb), and gimp (Everything that belong to GIMP)

def open_an_image(filename):  #Name of main function and variables

    img = pdb.gimp_image_new(1920, 1080, RGB)      #This function opens a new image with the size given and the image mode colors
    imagLayer = pdb.gimp_file_load_layer(img, filename)    #This will open or load image from directory
    pdb.gimp_image_add_layer(img, imagLayer, 0)            #Add or insert the layer for the image that it will open       
    #Center the image and make it big
    factor = min (float(img.width) / imagLayer.width, float(img.height) / imagLayer.height)
    imagLayer.scale(int(imagLayer.width * factor), int(imagLayer.height * factor))
    imagLayer.set_offsets((img.width - imagLayer.width) / 2, (img.height - imagLayer.height) / 2)
     
    pdb.gimp_display_new(img)
   
register(
    "open_an_image",
    "Open any image",           #Short description
    "Open any type of image",   #Long description
    "Your name",
    "Your name",
    "2021",
    "Open my favorite image",  #This is how you want it to appear in GIMP menu
    "",
    [   
    (PF_FILENAME, "filename", "Image:", None),  #Directory option
    ],
    [],
    open_an_image, menu="<Image>/Python-Fu/Open my favorite image"), #This is how you want it to appear in GIMP menu
main()

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 8:47 pm  (#7) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
Wow! So many people offered to help. Appreciate it. I feel bad I wasn't clearer about what my question is. My bad.

What I need to do really is very simple. Yes, I am trying to do with plug-in script the exact same thing as "File -> Open as layers" from the GIMP UI. When I do that, you are prompted for the file, and the png file gets loaded to a new layer, and your current layer becomes that newly loaded png. Very simple. Not so with the Python script. I can do color adjustment, sharping, and a bunch of other plug-ins - but I am stumped on this one.

filename=r"c:\Users\xxxx\Pictures\signature.png"
image = pdb.file_png_load(filename, filename)

I think the file is loaded because if I do this immediately after

name=image.name
width=image.width
height=image.height
pdb.gimp_message("%s: width=%d, height=%d\n"%(name,width,height))

I see the proper information displayed at the error console. But there is no new layer. I don't see any new layer like I normally get from the GIMP UI.

I wish there is a easy way for me to post a screen shot. Sallyanne, was that a screen shot you posted? How do you do that?


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 9:01 pm  (#8) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
I am going to try Pocholo's method:

imagLayer = pdb.gimp_file_load_layer(img, filename) #This will open or load image from directory
pdb.gimp_image_add_layer(img, imagLayer, 0) #Add or insert the layer for the image that it will open

Will let you know.


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 9:08 pm  (#9) 
Offline
New Member

Joined: Sep 29, 2021
Posts: 4
For screen shots in Gimp first I print screen from the keyboard. Alt print screen can also be used. Then I go to edit and paste as and choose new image.

ecs1749 wrote:
Wow! Sallyanne, was that a screen shot you posted? How do you do that?


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 9:10 pm  (#10) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
Yes!!! That works. So, I have to explicitly add the new layer.

Thanks, everyone.


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 9:14 pm  (#11) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
zeuspaul wrote:
For screen shots in Gimp first I print screen from the keyboard. Alt print screen can also be used. Then I go to edit and paste as and choose new image.

ecs1749 wrote:
Wow! Sallyanne, was that a screen shot you posted? How do you do that?


I know how to capture the screen but where do I paste it to? "edit and paste as"???

I try Ctrl-V and that doesn't work


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 9:21 pm  (#12) 
Offline
Global Moderator
User avatar

Joined: Apr 01, 2012
Posts: 7744
Location: On the other side of this screen
ecs1749 wrote:
I wish there is a easy way for me to post a screen shot. Sallyanne, was that a screen shot you posted? How do you do that?

There is a way to do it in gimp, file > create > screenshot But I always do it this way - I find it quicker.
Print the screen and paste in gimp as a new image then crop to what you want to show. If you are wanting to show a drop down menu you need to click over it and hold your cursor over the area while you take your screen shot.
You may have to have an image open as some things are 'unavailable/greyed out' when there is no image.

rich did a screen shot too and probably with a better answer. Theme of his gimp is just a different colour.

_________________


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 9:25 pm  (#13) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
sallyanne wrote:
ecs1749 wrote:
I wish there is a easy way for me to post a screen shot. Sallyanne, was that a screen shot you posted? How do you do that?

There is a way to do it in gimp, file > create > screenshot But I always do it this way - I find it quicker.
Print the screen and paste in gimp as a new image then crop to what you want to show. If you are wanting to show a drop down menu you need to click over it and hold your cursor over the area while you take your screen shot.
You may have to have an image open as some things are 'unavailable/greyed out' when there is no image.


That's all good but how do I paste it to this place? Do I have to create an image file and upload the image file? I hope not.


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 9:29 pm  (#14) 
Offline
Global Moderator
User avatar

Joined: Apr 01, 2012
Posts: 7744
Location: On the other side of this screen
After you have it you export it as an image and then post it as an image. By the way the red square I did on it I did after I had the picture in gimp - Just used a rectangle select and stroked that selection. you can add anything you need to on your image before you export it, then post.

_________________


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 9:47 pm  (#15) 
Offline
Global Moderator
User avatar

Joined: Apr 01, 2012
Posts: 7744
Location: On the other side of this screen
Sorry ecs. After you have the screenshot in your clipboard, To paste that into gimp first you go to "Menu in Gimp"
Edit> Paste As> New Image
Image
To do with keys it has the shortcul there as well
Also, Have a look at this viewtopic.php?f=23&t=7695

I'm guessing you haven't posted a picture on the message boards yet? If you want to, click on the icon in between the speech icon and the web icon, hold your cursor over it and it will say upload file. Click on it and you will get another window where you have to browse for your file and then add it. - It needs to upload and then you submit it. It will only give a web address for now until you have posted your post. Then you will see your image. By the way the maximum size file is 5242880 bytes.

_________________


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 9:53 pm  (#16) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
ecs1749 wrote:
Yes!!! That works. So, I have to explicitly add the new layer.

Thanks, everyone.

I'm glad I was be able to help! Keep learning, don't give up.
Make sure you add to the thread title "Solved".

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Unable to load an image as layer
PostPosted: Sat Oct 02, 2021 10:10 pm  (#17) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
sallyanne wrote:
Sorry ecs. After you have the screenshot in your clipboard, To paste that into gimp first you go to "Menu in Gimp"
Edit> Paste As> New Image
[ Image ]
To do with keys it has the shortcul there as well
Also, Have a look at this viewtopic.php?f=23&t=7695

I'm guessing you haven't posted a picture on the message boards yet? If you want to, click on the icon in between the speech icon and the web icon, hold your cursor over it and it will say upload file. Click on it and you will get another window where you have to browse for your file and then add it. - It needs to upload and then you submit it. It will only give a web address for now until you have posted your post. Then you will see your image. By the way the maximum size file is 5242880 bytes.


So, you do have to go through a file. No clipboard. Ok. Thanks,


Top
Post new topic Reply to topic  [ 17 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Watch Folder and load image as layer

1

No new posts Unable to export jpg after added a new layer

14

No new posts Unable to paint on transparent layer

1

No new posts script to load text file and create text layer

6

No new posts Attachment(s) Adding a image as a layer, moving layer, and then flattening

2



* Login  



Powered by phpBB3 © phpBB Group