Post Reply 

Create new images button & Save as override from Script-fu

Sep 5, 2014, 12:42
Post: #1
Create new images button & Save as override from Script-fu
Hi everyone,

I am new to Script-fu and this is my first post on this forum.

Does somebody can help me creating a button to create a new image with specific size & another button to save this image as jpeg to a specific location with a specific name and override if already exist ?

I am using Gimp 2.8 for Windows.

I made several attempt but I cannot managed to get anything work Sad

Thank you
Find all posts by this user
Quote this message in a reply
Sep 8, 2014, 11:36
Post: #2
RE: Create new images button & Save as override from Script-fu
Hello Kevin,
thank you for your reply.

I use this script to create my image :

(define (gimp-image-new 200 100 1)
)
(script-fu-register "script-fu-File-Image" ;; name of the script
"<Image>/File/New/Image" ;; position in the menu
"Create a layer, no dialog" ;;
"Autor" ;; autor
"Copyright" ;; copyright
"Date" ;; date
"" ;; type of images supported by the script
SF-IMAGE "Image" 0 ;; image where layer is added
SF-DRAWABLE "Drawable" 0 ;; active layer
) ;; end of register

But when I run the script I get this error message:
Error while executing script-fu-File-Image:
Error: (:2) eval: unbound variable: script-fu-File-Image

Thank you,
Benoit

(Sep 5, 2014 13:12)paynekj Wrote:  If you show us what you have done so far we can talk you through your problems.

Kevin
Find all posts by this user
Quote this message in a reply
Sep 9, 2014, 08:30
Post: #3
RE: Create new images button & Save as override from Script-fu
Thank you Kevin.

I can create my image!
Now I want to save it as jpg can you help me, here is my code:


(define (script-fu-File-Image)
(let* (
(image 0)
(layer 0)
)
(set! image (car (gimp-image-new 200 100 RGB)))
(set! layer (car (gimp-layer-new image 200 100 RGB-IMAGE "layer" 100 NORMAL)))
(gimp-image-insert-layer image layer 0 -1)
(gimp-context-set-background '(255 255 255))
(gimp-drawable-fill layer BACKGROUND-FILL)
(gimp-display-new image)
(gimp-displays-flush)
)
)

(define (FU_save-as-jpg)
(let* (
(image 0)
(drawable 0)
)
(gimp-image-set-filename image "name")
(file-jpeg-save 0 image drawable "name" "name" 1 1 1 1 "GIMP" 0 0 0 0 )
)
)

(script-fu-register "script-fu-File-Image" ;; name of the script
"<Image>/File/New/Benoit" ;; position in the menu
"Create a layer, no dialog" ;;
"Autor" ;; autor
"Copyright" ;; copyright
"Date" ;; date
"" ;; type of images supported by the script
) ;; end of register

(script-fu-register "FU_save-as-jpg" ;; name of the script
"Save as JPG"
"<Image>/File/Save as JPEG" ;; position in the menu
"Create a layer, no dialog" ;;
"Autor" ;; autor
"Copyright" ;; copyright
"Date" ;; date
"" ;; type of images supported by the script
) ;; end of register

(script-fu-menu-register "FU_save-as-jpg"
"<Image>/File/Save/"
)
Find all posts by this user
Quote this message in a reply
Sep 9, 2014, 13:03 (This post was last modified: Sep 9, 2014 13:05 by beniman.)
Post: #4
RE: Create new images button & Save as override from Script-fu
Thank you for all Kevin.

One last point:
this command has no effect:
(gimp-context-set-paint-method "gimp-paintbrush")

Do you have any clue ?

Here is my full code:

(define (script-fu-File-Image)
(let* (
(image 0)
(layer 0)
(method "gimp-paintbrush")
(brush "1. Pixel")
)
(set! image (car (gimp-image-new 200 100 RGB)))
(set! layer (car (gimp-layer-new image 200 100 RGB-IMAGE "layer" 100 NORMAL)))
(gimp-image-insert-layer image layer 0 -1)
(gimp-context-set-background '(255 255 255))
(gimp-drawable-fill layer BACKGROUND-FILL)
(gimp-context-set-paint-method "gimp-paintbrush")
(gimp-context-set-paint-mode 0)
(gimp-context-set-brush brush)
(gimp-context-set-brush-size 3)
(gimp-display-new image)
(gimp-displays-flush)
)
)

(define (FU_save-as-jpg image drawable)
(let* (
(filename "/Users/bde/Desktop/name.jpg")
(display 1)
)
(gimp-image-set-filename image filename)
(file-jpeg-save RUN-NONINTERACTIVE image drawable filename filename 1 1 1 1 "GIMP" 0 0 0 0 )
(gimp-display-delete display)
)

)

(script-fu-register "script-fu-File-Image" ;; name of the script
"<Image>/File/New/Benoit" ;; position in the menu
"Create a layer, no dialog" ;;
"Autor" ;; autor
"Copyright" ;; copyright
"Date" ;; date
"" ;; type of images supported by the script
) ;; end of register

(script-fu-register "FU_save-as-jpg" ;; name of the script
"Save as JPEG" ;;; menu label
"Export image as a JPEG" ;; tipstrip
"Copyright" ;; copyright
"selfauthor" ;; Author
"selffileversion" ;; date
"*" ;; image types
SF-IMAGE "Image" 0 ;; image
SF-DRAWABLE "Drawable" 0 ;; drawable
)

(script-fu-menu-register "FU_save-as-jpg" "<Image>/File/Save" )
Regards,
Benoit
Find all posts by this user
Quote this message in a reply
Sep 9, 2014, 13:50
Post: #5
RE: Create new images button & Save as override from Script-fu
(Sep 9, 2014 13:35)paynekj Wrote:  If you are expecting it to change the tool selected to the paintbrush in the toolbox then you will be disappointed. Scripts are not allowed to alter the user interface.

Kevin

Exactly, I want to set the paintbrush as the selected tool in the toolbox.

Those lines
(gimp-context-set-paint-mode 0)
(gimp-context-set-brush brush)
(gimp-context-set-brush-size 3)
are well executed and set the interface as expected.

As you said, "Scripts are not allowed to alter the user interface." Do you have any workaround to allow a tool to be selected when the file is created ?

Another point, do you know how I can set the location in the menu where the script will be inserted. I would like it at the top of the File menu.
Find all posts by this user
Quote this message in a reply
Sep 9, 2014, 14:40
Post: #6
RE: Create new images button & Save as override from Script-fu
Well ok thank you Kevin.
You have been very helpful.

We can close this thread.

Best regards,
Benoit
Find all posts by this user
Quote this message in a reply
Sep 10, 2014, 10:10
Post: #7
RE: Create new images button & Save as override from Script-fu
(Sep 9, 2014 14:52)ofnuts Wrote:  You can put the open menu in File>Create.

But if you use this often, you don't care where the menus entries show up because you can associate the create/save actions to a keyboard shortcut instead.

Nice hint !

My biggest concern is the ability to set the paintbrush as default tool in my script.
It seems possible as per this forum:
http://www.gimpchat.com/viewtopic.php?f=9&t=2113 reply of saulgoode
I know it is not the official forum but...

Sorry Kevin, but I am still asking this in case someone have the key.
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How do I save a image into a press quality PDF? Komodo 1 128 Aug 23, 2018 15:02
Last Post: paynekj
  Two images blended Lasse 1 113 Aug 20, 2018 20:10
Last Post: paynekj
  How do I save Paths? RogerTheShrubber 1 134 Aug 20, 2018 20:09
Last Post: paynekj
  Create a Rift AMaskedMan 1 284 Apr 20, 2018 15:47
Last Post: paynekj
  Resizing Images Swilson 1 264 Apr 14, 2018 05:47
Last Post: ythgilb

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS