Sat Dec 08, 2012 1:33 pm
; save_and_export.scm
; by Rob Antonishen
; http://silent9.com
; Version 1.2 (20091005)
; Changes:
; v1.1 added messagebox handler
; v1.2 added second script to allow save of xcf files or save-as to allow specifying the xcf
; Description
; Saves the current XCF file as well as a png and jpg in the
; same directory with the same name It uses the defaults for png and jpg
; and will overwrite any file already there.
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; The GNU Public License is available at
; http://www.gnu.org/copyleft/gpl.html
(define (save-as-and-export img inLayer inDir inFileRoot exportpng? exportjpg?)
(let*
(
(shortname (string-append inFileRoot ".xcf"))
(fullname (string-append inDir DIR-SEPARATOR shortname))
(realfullname (car (gimp-image-get-filename img)))
(dupimage (car (gimp-image-duplicate img)))
(temp 0)
)
;save the xcf file
(gimp-progress-set-text (string-append "Saving: " shortname))
(gimp-xcf-save 0 img (car (gimp-image-get-active-drawable img)) fullname shortname)
;reload the xcf - this is necessary if the original file was not an xcf or if the filname/path was changed!
(set! temp (car (gimp-file-load RUN-NONINTERACTIVE fullname shortname)))
(gimp-displays-reconnect img temp)
(gimp-image-clean-all temp)
;remove filename from fullname to get the path
(set! fullname (substring fullname 0 (- (string-length fullname) (string-length shortname))))
;strip old extension
(while (not (string=? (substring shortname (- (string-length shortname) 1)) "."))
(set! shortname (substring shortname 0 (- (string-length shortname) 1)))
)
(set! shortname (substring shortname 0 (- (string-length shortname) 1)))
(gimp-image-merge-visible-layers dupimage CLIP-TO-IMAGE)
(when (equal? exportpng? TRUE)
;save the png file
(gimp-progress-set-text (string-append "Saving: " (string-append shortname ".png")))
(file-png-save-defaults RUN-NONINTERACTIVE dupimage (car (gimp-image-get-active-drawable dupimage))
(string-append fullname shortname ".png")
(string-append shortname ".png")))
(when (equal? exportjpg? TRUE)
;save the jpeg file
(gimp-progress-set-text (string-append "Saving: " (string-append shortname ".jpg")))
(gimp-file-save RUN-NONINTERACTIVE dupimage (car (gimp-image-get-active-drawable dupimage))
(string-append fullname shortname ".jpg")
(string-append shortname ".jpg")))
;clean up
(gimp-image-delete dupimage)
)
)
(script-fu-register "save-as-and-export"
"<Image>/File/Save/Save-As XCF and Export..."
"Saves the current file as a specified XCF and exports a png and jpg as selected."
"Rob Antonishen"
"Rob Antonishen"
"Sept 2009"
"RGB* GRAY* INDEXED"
SF-IMAGE "image" 0
SF-DRAWABLE "drawable" 0
SF-DIRNAME "Save-as Directory" ""
SF-STRING "Save-as filename (without .xcf)" "filename"
SF-TOGGLE "Export a png" TRUE
SF-TOGGLE "Export a jpg" TRUE
)
(define (save-and-export img inLayer exportpng? exportjpg?)
(let*
(
(shortname (car (gimp-image-get-name img)))
(fullname (car (gimp-image-get-filename img)))
(handler (car (gimp-message-get-handler)))
)
(gimp-message-set-handler MESSAGE-BOX)
(if (= (string-length fullname) 0)
(gimp-message "The file must be saved before a backup can be made.")
(if (not (string-ci=? (substring shortname (- (string-length shortname) 4)) ".xcf"))
(gimp-message "The file must be an xcf.")
(save-as-and-export img inLayer
(substring fullname 0 (- (string-length fullname) (string-length shortname)))
(substring shortname 0 (- (string-length shortname) 4))
exportpng? exportjpg?)
)
)
(gimp-message-set-handler handler)
)
)
(script-fu-register "save-and-export"
"<Image>/File/Save/Save XCF and Export..."
"Re-saves the current XCF and exports a png and jpg as selected."
"Rob Antonishen"
"Rob Antonishen"
"Sept 2009"
"RGB* GRAY* INDEXED"
SF-IMAGE "image" 0
SF-DRAWABLE "drawable" 0
SF-TOGGLE "Export a png" TRUE
SF-TOGGLE "Export a jpg" TRUE
)
Mon Dec 10, 2012 6:53 am
Mon Dec 10, 2012 3:38 pm
PhotoComix wrote:1 ) Let pop out the warning about overwriting requiring to confirm
PhotoComix wrote:2 ) automatically rename (ie adding to the name , if already used ,a prefix as a progressive number )
Tue Dec 11, 2012 4:37 pm
Would you want both the XCF and PNG/JPG files renamed? Or the XCF overwritten and the PNG/JPG renamed?
What if the XCF exists and the PNG/JPG does not, would still you want the PNG/JPG renamed?
Tue Dec 11, 2012 6:11 pm
Tue Dec 11, 2012 6:28 pm
Wed Dec 12, 2012 4:28 am
Wed Dec 12, 2012 10:17 am
Fri Dec 14, 2012 2:54 pm
Fri Dec 14, 2012 4:48 pm
Fri Dec 14, 2012 6:49 pm
Tue Dec 18, 2012 3:40 pm
; backup_working.scm
; by Rob Antonishen
; http://silent9.com
; Version 1.3 (20120301)
; Changes:
; 1.1 changes to use xcfgz compressed files
; 1.2 added option to limit the number of files backed up.
; This has changed the naming convention to include the original extension
; 1.3 added option to also export a png and/or jpeg file
; Description
; Saves a backup copy as [imagename-ext]-YYYY-MM-DD-HH-MM.XCFGZ
; It will appear in the File menu. and can easily accessed with Alt-F, B
; License:
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; The GNU Public License is available at
; http://www.gnu.org/copyleft/gpl.html
(define (backup-working img inLayer exportpng? exportjpg?)
(let*
(
(timestamp (unbreakupstr
(append (list (number->string (+ 1900 (car (time))))) ; year
(map (lambda (x) (string-append (make-string (- 2 (string-length (number->string x))) #\0) (number->string x))) ; pad to two characters
(append (list (+ 1 (cadr (time)))) (butlast (cddr (time)))))) "-")) ; month is 0 referenced when (time) returns it
(filename "")
(extension "")
(dirname "")
(dupimage (car (gimp-image-duplicate img)))
(maxbackups 0) ; Change this to define the number of backup files to keep!!!
(filelist "")
)
;;helper defines
(define split
(lambda (ls)
(letrec ((split-h (lambda (ls ls1 ls2)
(cond
((or (null? ls) (null? (cdr ls)))
(cons (reverse ls2) ls1))
(else (split-h (cddr ls)
(cdr ls1) (cons (car ls1) ls2)))))))
(split-h ls ls '()))))
(define merge
(lambda (pred ls1 ls2)
(cond
((null? ls1) ls2)
((null? ls2) ls1)
((pred (car ls1) (car ls2))
(cons (car ls1) (merge pred (cdr ls1) ls2)))
(else (cons (car ls2) (merge pred ls1 (cdr ls2)))))))
;pred is the comparison, i.e. <= for an ascending numeric list, or
;string<=? for a case sensitive alphabetical sort,
;string-ci<=? for a case insensitive alphabetical sort,
(define merge-sort
(lambda (pred ls)
(cond
((null? ls) ls)
((null? (cdr ls)) ls)
(else (let ((splits (split ls)))
(merge pred
(merge-sort pred (car splits))
(merge-sort pred (cdr splits))))))))
(define get-n-items
(lambda (lst num)
(if (> num 0)
(cons (car lst) (get-n-items (cdr lst) (- num 1)))
'()))) ;'
(define slice
(lambda (lst start count)
(if (> start 1)
(slice (cdr lst) (- start 1) count)
(get-n-items lst count))))
; It Starts Here....
;---------------------
(if (= (string-length (car (gimp-image-get-filename img))) 0)
(gimp-message "The file must be saved before a backup can be made.")
(begin
(set! filename (unbreakupstr (butlast (strbreakup (car (gimp-image-get-name img)) ".")) "."))
(set! extension (car (last (strbreakup (car (gimp-image-get-name img)) "."))))
(set! dirname (unbreakupstr (butlast (strbreakup (car (gimp-image-get-filename img)) DIR-SEPARATOR)) DIR-SEPARATOR))
;update progressbar text
(gimp-progress-set-text (string-append "Backing up as: " filename "-" extension "-" timestamp ".xcfgz"))
;save file
(gimp-xcf-save 0 dupimage (car (gimp-image-get-active-drawable dupimage))
(string-append dirname DIR-SEPARATOR filename "-" extension "-" timestamp ".xcfgz")
(string-append filename "-" extension "-" timestamp ".xcfgz"))
;flatten duplicate
(gimp-image-merge-visible-layers dupimage CLIP-TO-IMAGE)
(when (equal? exportpng? TRUE)
;save the png file
(gimp-progress-set-text (string-append "Saving: " filename "-" extension "-" timestamp ".png"))
(file-png-save-defaults RUN-NONINTERACTIVE dupimage (car (gimp-image-get-active-drawable dupimage))
(string-append dirname DIR-SEPARATOR filename "-" extension "-" timestamp ".png")
(string-append filename "-" extension "-" timestamp ".png")))
(when (equal? exportjpg? TRUE)
;save the jpeg file
(gimp-progress-set-text (string-append "Saving: " filename "-" extension "-" timestamp ".jpg"))
(file-png-save-defaults RUN-NONINTERACTIVE dupimage (car (gimp-image-get-active-drawable dupimage))
(string-append dirname DIR-SEPARATOR filename "-" extension "-" timestamp ".jpg")
(string-append filename "-" extension "-" timestamp ".jpg")))
)
)
;clean up
(gimp-image-delete dupimage)
;delete extra backups
(when (> maxbackups 0)
(set! filelist (merge-sort string<=? (cadr (file-glob (string-append dirname DIR-SEPARATOR filename "-" extension "-*.xcfgz") 0))))
(set! filelist (slice filelist 0 (max (- (length filelist) maxbackups) 0)))
(map (lambda (x) (file-delete x)) filelist)
)
)
)
(script-fu-register "backup-working"
"<Image>/File/Save a _Backup"
"Saves a backup copy as [imagename-ext]-YYYY-MM-DD-HH-MM.XCFGZ"
"Rob Antonishen"
"Rob Antonishen"
"March 2012"
"*"
SF-IMAGE "image" 0
SF-DRAWABLE "drawable" 0
SF-TOGGLE "Also export a png" FALSE
SF-TOGGLE "Also export a jpg" FALSE
)
Thu Dec 20, 2012 1:33 pm