It is currently Mon Jul 22, 2024 12:24 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 20 posts ] 
Author Message
 Post subject: help pls layer on my image[resolved]
PostPosted: Wed Jul 09, 2014 4:32 am  (#1) 
Offline
GimpChat Member

Joined: Jul 09, 2014
Posts: 11
how can i add a layer to my current image in script-fu?


Last edited by croccaroc96 on Wed Jul 09, 2014 8:52 am, edited 1 time in total.

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: help pls layer on my image
PostPosted: Wed Jul 09, 2014 5:34 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
(NewLayer (car (gimp-layer-new Image yourwidth yourheight RGB "new" 100 NORMAL)))
(gimp-image-add-layer Image NewLayer -1)

Image=the name of your current image

_________________
"Where am I ?"


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 5:36 am  (#3) 
Offline
GimpChat Member

Joined: Jul 09, 2014
Posts: 11
where do i find my image name?


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 6:01 am  (#4) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
dinasset wrote:
(NewLayer (car (gimp-layer-new Image yourwidth yourheight RGB "new" 100 NORMAL)))
(gimp-image-add-layer Image NewLayer -1)

Image=the name of your current image


Image is NOT the name of the image. It is an ID number.

@croccaroc96

How are you running your script: From a menu or from the command line?

If from a menu, then your script will be passed the ID number of the image if you have defined a SF-IMAGE parameter in the registration.

If from the command line then your script will have to load the image using something like gimp-file-load which will return the ID number.

Kevin


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 6:02 am  (#5) 
Offline
GimpChat Member

Joined: Jul 09, 2014
Posts: 11
ok thank you kevin :D in this moment i'm scripting with the console but later i will save it and run it by the menu


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 6:14 am  (#6) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
In Python:
layer=gimp.Layer(image,'Added layer',100,100,RGBA_IMAGE)
image.add_layer(layer,0)


If this is a script that you add in a menu, it will typically take at least one argument, which is set by Gimp to the current image, and a very often a second one which is filled with the current layer.

On the python console, if you have one single image.
image=gimp.image_list()[0]


If you have several images but you know the name of the one you want:
image=[i for i in gimp.image_list() if i.name == 'TheImageName'][0]

_________________
Image


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 6:19 am  (#7) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
paynekj wrote:
dinasset wrote:
(NewLayer (car (gimp-layer-new Image yourwidth yourheight RGB "new" 100 NORMAL)))
(gimp-image-add-layer Image NewLayer -1)

Image=the name of your current image


Image is NOT the name of the image. It is an ID number.

....
Kevin

Yes, Kevin. A typo

_________________
"Where am I ?"


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 7:02 am  (#8) 
Offline
GimpChat Member

Joined: Jul 09, 2014
Posts: 11
my script (not working):

(define (script-fu-practise-myscript image Drawable) (let* ( (theImageWidth 1280) (theImageHeight 768) (layer (car (gimp-layer-new image theImageWidth theImageHeight 2 "nero" 100 4) ) ) ) (gimp-image-add-layer image layer 0) (gimp-context-set-background '(0 0 0) ) (gimp-context-set-foreground '(255 255 255) ) (gimp-drawable-fill layer BACKGROUND-FILL) (plug-in-grid 0 image layer 2 8 0 '(255 255 255) 100 2 8 0 '(255 255 255) 100 2 8 0 '(255 255 255) 100) (plug-in-gauss 0 image layer 8 8 1) (let* ( (visible (car (gimp-layer-new-from-visible image image "visible")))) (gimp-image-add-layer image visible 0)(plug-in-c-astretch 0 image visible))))


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 7:17 am  (#9) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
paynekj wrote:
If from the command line then your script will have to load the image using something like gimp-file-load which will return the ID number.

One can obtain the ID number of an already loaded image by opening the "Image->Canvas size..." dialog and noting the number that follows the hyphen in the image name at the very top. After you have noted the ID, close the dialog with the Cancel button. (A similar approach will work for layers, channels, and paths -- just find a suitable dialog.)
Attachment:
image-id.png
image-id.png [ 20.73 KiB | Viewed 3666 times ]

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 7:25 am  (#10) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
croccaroc96 wrote:
my script (not working):


Please use [ code ] [ / code ] tags to post code. It makes it so much easier to read:
(define (script-fu-practise-myscript image Drawable)
  (let* (
          (theImageWidth 1280)
          (theImageHeight 768)
          (layer (car (gimp-layer-new image theImageWidth theImageHeight 2 "nero" 100 4) ) )
        )
        (gimp-image-add-layer image layer 0)
        (gimp-context-set-background '(0 0 0) )
        (gimp-context-set-foreground '(255 255 255) )
        (gimp-drawable-fill layer BACKGROUND-FILL)
        (plug-in-grid 0 image layer 2 8 0 '(255 255 255) 100 2 8 0 '(255 255 255) 100 2 8 0 '(255 255 255) 100)
        (plug-in-gauss 0 image layer 8 8 1)
        (let* (
                (visible (car (gimp-layer-new-from-visible image image "visible")))
              )
              (gimp-image-add-layer image visible 0)
              (plug-in-c-astretch 0 image visible)
        )
  )
)

(script-fu-register "script-fu-practise-myscript"
                    "Practice My Script"
                    "tipstrip"
                    "copyright"
                    "author"
                    "fileversion"
                    ""
                    SF-IMAGE "Input Image" 0
                    SF-DRAWABLE "Input Drawable" 0
                    )

(script-fu-menu-register "script-fu-practise-myscript" "<Image>/contributed")


When I run your code I get the following error message:
Calling error for procedure 'gimp-image-add-layer':
Image 'Untitled' (1) is of type 'rgb', but an image of type 'gray' is expected


What type of image are you starting with? RGB/Greyscale/Indexed? as you have created a new layer with mode 2 = Grayscale (better if you use the predefined constants: GRAY-IMAGE etc) but then tried to add it to an RGB image.

Kevin


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 7:41 am  (#11) 
Offline
GimpChat Member

Joined: Jul 09, 2014
Posts: 11
ok new code working:

(let* ( (theImageWidth  30) (theImageHeight 38) (layer (car (gimp-layer-new 1 theImageWidth theImageHeight 2 "nero" 100 4) ) ) ) (gimp-image-convert-grayscale 1) (gimp-image-add-layer 1 layer 0) (gimp-context-set-background '(0 0 0) ) (gimp-context-set-foreground '(255 255 255) ) (gimp-drawable-fill layer BACKGROUND-FILL) (gimp-layer-resize-to-image-size layer) (plug-in-grid 0 1 layer 2 8 0 '(255 255 255) 100 2 8 0 '(255 255 255) 100 2 8 0 '(255 255 255) 100) (plug-in-gauss 0 1 layer 8 8 1) (let* ( (visible (car (gimp-layer-new-from-visible 1 1 "visible")))) (gimp-image-add-layer 1 visible 0)(plug-in-c-astretch 0 1 visible)))


the nuber 1 stay for the image id. now i need to put this script in the script-fu menu and i need to auto-identify the image id. can someone help me?


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 7:51 am  (#12) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
croccaroc96 wrote:
ok new code working:
the nuber 1 stay for the image id. now i need to put this script in the script-fu menu and i need to auto-identify the image id. can someone help me?


See my example of your code where I added the menu registration: viewtopic.php?f=9&t=10697#p141676

Kevin


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 8:03 am  (#13) 
Offline
GimpChat Member

Joined: Jul 09, 2014
Posts: 11
i need to edit something? because it gives me an error while trying to reload scripts


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 8:03 am  (#14) 
Offline
GimpChat Member

Joined: Jul 09, 2014
Posts: 11
(script-fu-register "script-fu-practise-myscript"
                    "Practice My Script"
                    "tipstrip"
                    "copyright"
                    "author"
                    "fileversion"
                    ""
                    SF-IMAGE "Input Image" 0
                    SF-DRAWABLE "Input Drawable" 0
                    )

(script-fu-menu-register "script-fu-practise-myscript" "<Image>/contributed")

this is right?


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 8:09 am  (#15) 
Offline
GimpChat Member

Joined: Jul 09, 2014
Posts: 11
it now looks like this:

script:

(define (script-fu-practise-myscript image Drawable)

(let* ( (theImageWidth  30) (theImageHeight 38) (layer (car (gimp-layer-new image theImageWidth theImageHeight 2 "nero" 100 4) ) ) ) (gimp-image-convert-grayscale 1) (gimp-image-add-layer image layer 0) (gimp-context-set-background '(0 0 0) ) (gimp-context-set-foreground '(255 255 255) ) (gimp-drawable-fill layer BACKGROUND-FILL) (gimp-layer-resize-to-image-size layer) (plug-in-grid 0 image layer 2 8 0 '(255 255 255) 100 2 8 0 '(255 255 255) 100 2 8 0 '(255 255 255) 100) (plug-in-gauss 0 image layer 8 8 1) (let* ( (visible (car (gimp-layer-new-from-visible image image "visible")))) (gimp-image-add-layer image visible 0)(plug-in-c-astretch 0 image visible)))

(script-fu-register "script-fu-practise-myscript"
                    "Practice My Script"
                    "tipstrip"
                    "copyright"
                    "author"
                    "fileversion"
                    ""
                    SF-IMAGE "Input Image" 0
                    SF-DRAWABLE "Input Drawable" 0
                    )

(script-fu-menu-register "script-fu-practise-myscript" "<Image>/contributed")


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 8:16 am  (#16) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
You are missing a parenthesis. try this:
(define (script-fu-practise-myscript image Drawable)
  (let* (
          (theImageWidth  30)
          (theImageHeight 38)
          (layer (car (gimp-layer-new image theImageWidth theImageHeight 2 "nero" 100 4) ) ) )
          (gimp-image-convert-grayscale 1)
          (gimp-image-add-layer image layer 0)
          (gimp-context-set-background '(0 0 0) )
          (gimp-context-set-foreground '(255 255 255) )
          (gimp-drawable-fill layer BACKGROUND-FILL)
          (gimp-layer-resize-to-image-size layer)
          (plug-in-grid 0 image layer 2 8 0 '(255 255 255) 100 2 8 0 '(255 255 255) 100 2 8 0 '(255 255 255) 100)
          (plug-in-gauss 0 image layer 8 8 1)
          (let* (
                  (visible (car (gimp-layer-new-from-visible image image "visible")))
                )
                (gimp-image-add-layer image visible 0)(plug-in-c-astretch 0 image visible)
          )
  )
)

(script-fu-register "script-fu-practise-myscript"
                    "Practice My Script"
                    "tipstrip"
                    "copyright"
                    "author"
                    "fileversion"
                    ""
                    SF-IMAGE "Input Image" 0
                    SF-DRAWABLE "Input Drawable" 0
                    )

(script-fu-menu-register "script-fu-practise-myscript" "<Image>/contributed")


Kevin


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 8:18 am  (#17) 
Offline
GimpChat Member

Joined: Jul 09, 2014
Posts: 11
no errors now. in which menu i find it?


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 8:19 am  (#18) 
Offline
GimpChat Member

Joined: Jul 09, 2014
Posts: 11
omg *facepalm* sorry for the question XD


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 8:22 am  (#19) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
croccaroc96 wrote:
omg *facepalm* sorry for the question XD


;) Remember that question when you write a script for someone else and give them the answer before they ask.

Kevin


Top
 Post subject: Re: help pls layer on my image
PostPosted: Wed Jul 09, 2014 8:23 am  (#20) 
Offline
GimpChat Member

Joined: Jul 09, 2014
Posts: 11
thanks to all :D now it works :D :D :D

special thanks to kevin :D


Top
Post new topic Reply to topic  [ 20 posts ] 

All times are UTC - 5 hours [ DST ]


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

2

No new posts Attachment(s) Unable to load an image as layer

16

No new posts Attachment(s) Image Layer Disappears When I Move It

4

No new posts Watch Folder and load image as layer

1

No new posts Selection pasting only transparency - single layer image [Solved]

3



* Login  



Powered by phpBB3 © phpBB Group