Script-fu gimp-file-save-thumbnail function
This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
Script-fu gimp-file-save-thumbnail function | Martin Bradley | 04 Jan 15:12 |
Script-fu gimp-file-save-thumbnail function | Kevin Cozens | 04 Jan 17:50 |
Script-fu gimp-file-save-thumbnail function | Martin Bradley | 04 Jan 23:35 |
Script-fu gimp-file-save-thumbnail function | Kevin Cozens | 05 Jan 02:59 |
Script-fu gimp-file-save-thumbnail function | Joao S. O. Bueno | 05 Jan 03:15 |
Script-fu gimp-file-save-thumbnail function | Martin Bradley | 07 Jan 20:30 |
Script-fu gimp-file-save-thumbnail function | Manish Singh | 08 Jan 03:56 |
Script-fu gimp-file-save-thumbnail function
Hi Folks,
I'm trying to use this script to create a thumbnail of a jpg or gif image. However I am not getting any results, no new image stored.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;;;; Image Process Gimp script
;;;;
;;;; To run this from the command prompt:
;;;; gimp -c -d -i -b '(script-fu-create-thumb "file.jpg")' \
;;;; '(gimp-quit 0)'
;;
(define (script-fu-create-thumb filename)
(let* ((img 0))
;; car needed here because gimp functions return values as lists
(set! img (car (gimp-file-load 1 filename filename))
(gimp-file-save img filename)
(print (gimp-file-save-thumbnail img filename))))
)
(script-fu-register "script-fu-create-thumb"
"/Xtns/Script-Fu/Utils/Thumbnail..."
"Thumbnail Image"
"Marty Bradley"
"Marty Bradley"
"Dec 2007"
""
SF-VALUE "Image Name" " ")
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Later on I edited the function to be as shown below. Only the first gimp-message was output so maybe the gimp-file-load is not sucessful.
(define (script-fu-create-thumb filename)
(let* ((img 0))
;; car needed here because gimp functions return values as lists
(gimp-message "About to start the thumbnail save")
(set! img (car (gimp-file-load 1 filename filename))
(if img
(gimp-message "Image not nil")
(gimp-message "Image is NIL!!!!!"))
(gimp-file-save img filename)
(when (gimp-file-save-thumbnail img)
(gimp-message "thumbnail saved?")))))
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
My System Details
Debian etch 4.0.
Linux debian 2.6.18-5-486
GIMP version 2.2.13
This is my first work with script-fu and to my shame I don't know much about Gimp. Any help is appreciated.
thanks, Martin
Script-fu gimp-file-save-thumbnail function
Martin Bradley wrote:
(define (script-fu-create-thumb filename) (let* ((img 0))
;; car needed here because gimp functions return values as lists (set! img (car (gimp-file-load 1 filename filename)) (gimp-file-save img filename)
(print (gimp-file-save-thumbnail img filename)))) )
[snip]
> SF-VALUE "Image Name" " "
You have an error in your placement of ')'. You have one too few at the end of the set! line and one too many at the end of the print line.
You have the wrong number of arguments in the call to gimp-file-save. You can see the list of required arguments in the Procedure Browser. I don't think you need the file save since you haven't changed the file since it was loaded.
The SF-VALUE in the register block should be SF-FILENAME.
Later on I edited the function to be as shown below.
[snip]
(when (gimp-file-save-thumbnail img) (gimp-message "thumbnail saved?")))))
Where did you come up with 'when'? There is no such function in Script-Fu.
Script-fu gimp-file-save-thumbnail function
Hi Folks,
You have an error in your placement of ')'.
That was because I thought set was used similar to (let ..)
I don't think you need the file save since you haven't changed the file since it was loaded.
I have corrected the arguments. I saved the file first because gimp-file-save-thumbnail documentation suggested to do so. I've since removed it.
The SF-VALUE in the register block should be SF-FILENAME.
Yes, had already manage to correct this.
Where did you come up with 'when'? There is no such function in Script-Fu.
I'd been slowly trying to learn Common Lisp and thought that Script-Fu had it.
Here is the scheme coding tutorial I was using, most likely the wrong
thing to be reading.
http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-1.html#node_toc_node_sec_4.1
(define (script-fu-create-thumb filename)
(let* ((img 0))
;; car needed here because gimp functions return values as lists
(set! img (car (gimp-file-load 1 filename filename)))
(gimp-file-save-thumbnail img filename)))
(script-fu-register "script-fu-create-thumb"
"/Xtns/Script-Fu/Utils/Thumbnail..."
"Thumbnail Image"
"Marty Bradley"
"Marty Bradley"
"Dec 2007"
""
SF-FILENAME "Image Name" " ")
thank you, Martin
Script-fu gimp-file-save-thumbnail function
Martin Bradley wrote:
I'd been slowly trying to learn Common Lisp and thought that Script-Fu had it. Here is the scheme coding tutorial I was using, most likely the wrong thing to be reading.
http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-1.html#node_toc_node_sec_4.1
Script-Fu scripts are based on the Scheme language. Scheme is a dialect of Lisp. There are a number of Scheme interpreters which may offer slightly different features and compliance with the Scheme standards. The web page you are reading appears to be for the Scheme variant used in mzscheme.
Script-Fu as of GIMP 2.4 more closely follows the R5RS. The document you
should be reading can be found at
http://www.schemers.org/Documents/Standards/R5RS/r5rs.pdf.
Some aspects described in the R5RS are not supported in Script-Fu. define-syntax is one of them.
Script-fu gimp-file-save-thumbnail function
On Friday 04 January 2008 19:35, Martin Bradley wrote:
Hi Folks,
You have an error in your placement of ')'.
That was because I thought set was used similar to (let ..)
I don't think you need the file save since you haven't changed the file since it was loaded.
I have corrected the arguments. I saved the file first because gimp-file-save-thumbnail documentation suggested to do so. I've since removed it.
The SF-VALUE in the register block should be SF-FILENAME.
Yes, had already manage to correct this.
Where did you come up with 'when'? There is no such function in Script-Fu.
I'd been slowly trying to learn Common Lisp and thought that Script-Fu had it. Here is the scheme coding tutorial I was using, most likely the wrong thing to be reading. http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-1.html# node_toc_node_sec_4.1
(define (script-fu-create-thumb filename) (let* ((img 0))
;; car needed here because gimp functions return values as lists (set! img (car (gimp-file-load 1 filename filename))) (gimp-file-save-thumbnail img filename)))(script-fu-register "script-fu-create-thumb" "/Xtns/Script-Fu/Utils/Thumbnail..." "Thumbnail Image" "Marty Bradley"
"Marty Bradley"
"Dec 2007"
""
SF-FILENAME "Image Name" " ")
May I suugest this code instead of the above? :
from gimpfu import * def python_fu_create_thumb(filename): img = pdb.gimp_file_load(filename, filename) pdb.gimp_file_save_thumbnail(img, filename)
register (
"python-fuc-create-thumb",
"Create Thumbnail of Image File",
"Create Thumbnail of Image File",
"Marty Bradley",
"Marty Bradley",
"jan 2008",
"",
"/Xtns/Script-Fu/Utils/Thumbnail...",
[(PF_FILENAME, "Image Name". "Filename of the iamge to create
thumbnail", "")],
[],
python_fu_create_thumb
)
main()
So, but for the many parameters to the regiser function, (whuch IMHO is a missdesign of the python bindings), you have just two lines of code which are very straight and readable. No need to match odd parenthesis, no need to worry about lists, and getting elements inside lists, no need to pre-declare variable in an obscure "let" statement.
regards,
js ->
thank you,
Martin
Script-fu gimp-file-save-thumbnail function
Hi Joao,
May I suugest this code instead of the above? :
from gimpfu import * def python_fu_create_thumb(filename): img = pdb.gimp_file_load(filename, filename) pdb.gimp_file_save_thumbnail(img, filename)
register ( "python-fuc-create-thumb",
"Create Thumbnail of Image File", "Create Thumbnail of Image File", "Marty Bradley",
"Marty Bradley",
"jan 2008",
"",
"/Xtns/Script-Fu/Utils/Thumbnail...", [(PF_FILENAME, "Image Name". "Filename of the iamge to create thumbnail", "")],
[],
python_fu_create_thumb
)
main()
I don't want to try to get your code working because I know nothing about Python, I know it is a good language. The other reason I'm not happy using it is that it adds another layer of software to a solution that should work on its own.
I have still been unable to get the following to work.
(define (script-fu-create-thumb filename)
(let* ((img 0))
;; car needed here because gimp functions return values as lists
(set! img (car (gimp-file-load 1 filename filename)))
(gimp-file-save-thumbnail img filename)))
(script-fu-register "script-fu-create-thumb"
"/Xtns/Script-Fu/Utils/Thumbnail..."
"Thumbnail Image"
"Marty Bradley"
"Marty Bradley"
"Dec 2007"
""
SF-FILENAME "Image Name" " ")
Any other pointers would be gladly accepted.
regards, Martin.
Script-fu gimp-file-save-thumbnail function
On Mon, Jan 07, 2008 at 07:30:22PM +0000, Martin Bradley wrote:
I don't want to try to get your code working because I know nothing about Python, I know it is a good language. The other reason I'm not happy using it is that it adds another layer of software to a solution that should work on its own.
If you don't want to learn Python that's fine, but please don't spread made up misinformation. PyGIMP and Script-fu both talk to the GIMP PDB directly, there is no extra layer in the Python case.
-Yosh