Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use script-fu for loading images stored in files?
#1
I am trying to manipulate images stored in files.
As a first exercise, I tried to open an image, and then save it to a file 
with another name. Note both the source and the destination files already 
exist in the file system before my manipulation. I do not mind overwriting 
the contents of the destination file.
The code I have tried is:
Code:
(script-fu-register
   "copy"             ;func name
   "copy"             ;func label
   "Copy a file containing an image to another file. Both file exist in the file system. The destination file will be overwritten."                ;description
   ""                 ;author
   ""                 ;copyright notice
   ""                 ;date created
   ""                 ;image type that the script works on
   SF-FILENAME    "Input file"     ""
   SF-FILENAME    "Output file"    ""
)
(script-fu-menu-register "copy" "<Image>/Image/Transform/")

(define (copy inImgFile outImgFile)
   (let* (
              (image (car (gimp-file-load
                           RUN-INTERACTIVE
                           inImgFile
                          )
                     )
              )
             (gimp-file-save
               RUN-INTERACTIVE
               image
               outImgFile
               %NULL
              )
         )  
   )
)
When running this code, I am prompted to choose the input and output files. There also seems to be a brief
message at the bottom of the screen about one of gimp-file-load or gimp-file-save. Other then that, nothing
happens. In particular, nothing seems to change for the output file.
If I run gimp from the terminal, and quit gimp after running this script-fu I get (in the terminal)
Message in the terminal Wrote:INFO: a stray image seems to have been left around by a plug-in: "[name of the input file, without extension] (imported)"
What am I doing wrong?
Reply
#2
According to that message you have loaded the image successfully but you still have to display it.
Sorry that I can't help you on how to do this:  Script-Fu is like alien for me.
Reply
#3
Much the same as previous comment. script-fu much the same as sanskrit Wink So do not ask me any difficult questions.

This might get you started. The image is open in Gimp. you need to add the file type you require to the new filename.
That %NULL - replace with quotes " "

   

Code:
(script-fu-register
   "script-fu-quick-save"  ;func name
   "quick-save"    ;menu label
   " "    ;description
   " "    ;author
   " "    ;copyright notice
   " "    ;date created
   "*"    ;image type that the script works on
   SF-IMAGE    "Image"                 0
   SF-DRAWABLE "Drawable"              0
   SF-DIRNAME "out-folder"            ""
   SF-STRING "file-out"               ""

)
(script-fu-menu-register "script-fu-quick-save" "<Image>/Tools")

(define (script-fu-quick-save image drawable out-folder file-out)


   (let* ((output (string-append out-folder "/" file-out)))

   ;start
   (gimp-context-push)
   (gimp-image-undo-group-start image)
   
   ;put your procedures here


   (gimp-file-save RUN-NONINTERACTIVE image output  "")


   (gimp-image-clean-all image)

   ;finish
   (gimp-image-undo-group-end image)
   (gimp-context-pop)
   (gimp-displays-flush)
)
)
Reply


Forum Jump: