; The GIMP -- an image manipulation program ; Copyright (C) 1995 Spencer Kimball and Peter Mattis ; ; Continuous Save --- save the file which named "base-name_(number).(type)" ; Copyright (C) 2001 Iccii ; ; Modified by Tamubun ; ; This script was born of miyoken's idea. ; ; -------------------------------------------------------------------- ; - Changelog - ; version 0.1 2001/05/20 iccii ; - Initial relase ; version 0.2 2001/05/24 iccii ; - Make better ; version 0.3 2001/05/24 iccii ; - Chose the filename with directory ; - Saved image type equal to original image type ; version 0.3a 2001/09/26 iccii ; - Bug fixed in checking the file type ; ; ==== ; ; version 0.4-tamubun ; 2005/03/11 tamubun ; - Added "Digits" option, and changed the file names for each layer. ; - Added "Reverse Order" option, to control output ordering. ; (To use the original ordering, i.e. from top layer to bottom ; layer, "Reverse Ordering" must be checked.) ; - Unified "JPEG Compression" option and "PNG Compression" option ; to single "Quality" option. ; - Deleted "Interactive" option. ; version 0.5-tamubun ; 2005/03/29 tamubun ; - Added "Start Number" option. ; version 0.6-tamubun ; 2005/04/06 tamubun ; - Added "#" convention. ; ; ==== ; version 0.6.1-mieki256 ; - Added "(gimp-drawable-fill tmp-layer TRANS-IMAGE-FILL)" ; - replace jpg-comp , png-comp ; version 0.6.2-mieki256 ; - GIMP 2.4 supported. (SF-FILENAME -> SF-DIRNAME + SF-STRING) ; -------------------------------------------------------------------- ; ; 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. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ; (define (script-fu-continuous-save-trans-img-fill img ; IMAGE drawable ; DRAWABLE (no need) dirname ; save directory name basefilename ; base file name save-type ; saving image type jpgcomp ; JPEG compression (0-100%) pngcomp ; PNG compression (level 1-9) digits ; trailing 0's start ; start number revfg ; If true, order from top to bottom interactive ; interactive save option on each layer ) ;; save bmp file (define (to-save-bmp img layer fn interactive) (file-bmp-save interactive img (car (gimp-image-flatten img)) fn "")) ;; save jpg file (define (to-save-jpg img layer fn interactive compq) (file-jpeg-save interactive img (car (gimp-image-flatten img)) fn "" (/ compq 100) 0.0 1 0 "" 0 0 0 1)) ;; save png file (define (to-save-png img layer fn interactive compq) (file-png-save interactive img layer fn "" 0 compq 1 1 1 1 1)) ;; make save filename (define (gen-fname fn start count ext) (let* ((zeros "0000000000") (str (number->string (+ start count))) (num (string-append zeros str)) (pos (- (string-length num) (max digits (string-length str))))) (string-append fn (substring num pos) ext))) ;; main job (let* ((count 0) (interactive-save (if (eqv? interactive TRUE) 0 1)) (number (car (gimp-image-get-layers img))) (image-type (car (gimp-image-base-type img))) (fn (string-append dirname "/" basefilename)) (fnlen (string-length fn)) ) ; end variable definition ; filename is "hoge/#" -> "hoge/" (if (and (> fnlen 0) ; filename is not "" (not (char=? #\/ (string-ref fn (- fnlen 1)))) ; last char is not "/" (string=? "#" (car (last (strbreakup fn "/"))))) ; last char is "#" (set! fn (substring fn 0 (- fnlen 1)))) ; loop all layer (while (< count number) (let* ( ;; get image-type (tmp-image-type (cond ((and (eqv? save-type 0) (eqv? image-type 2)) 0) ;; convert to RGB because BMP can't treat INDEXED image ((and (eqv? save-type 1) (or (eqv? image-type 1) (eqv? image-type 2))) 0) ;; convert to RGB because JPEG can't treat INDEXED and GRAY image (image-type) ;; otherwise, equal to origianl image type )) ;; get layer ID (layer (vector-ref (cadr (gimp-image-get-layers img)) (if (eqv? revfg 1) count (- number 1 count)))) ;; get layer width and height (width (car (gimp-drawable-width layer))) (height (car (gimp-drawable-height layer))) (tmp-img (car (gimp-image-new width height tmp-image-type))) (tmp-layer (car (gimp-layer-new tmp-img width height (+ 1 (* 2 tmp-image-type)) "Temp Layer" 100 NORMAL-MODE))) ) ;; create an image with single layer, and remove the layer mask (if exists) ;; ----- mieki256 add ----- (gimp-drawable-fill tmp-layer TRANS-IMAGE-FILL) (gimp-image-add-layer tmp-img tmp-layer 0) ;; ----- tamubun original ----- ;; (gimp-edit-clear tmp-layer) (gimp-edit-copy layer) (gimp-floating-sel-anchor (car (gimp-edit-paste tmp-layer 0))) (if (< 0 (car (gimp-layer-mask layer))) (let* ((tmp-mask (car (gimp-layer-create-mask tmp-layer 0)))) (gimp-edit-copy (car (gimp-layer-mask layer))) (gimp-floating-sel-anchor (car (gimp-edit-paste tmp-layer 0))) (gimp-image-remove-layer-mask tmp-img tmp-layer MASK-APPLY) (gimp-displays-flush))) ;(set! tmp-display (car (gimp-display-new tmp-img))) ;(gimp-displays-flush) ;; save a resulting image by specified image type (cond ((eqv? save-type 0) (to-save-bmp tmp-img tmp-layer (gen-fname fn start count ".bmp") interactive-save)) ((eqv? save-type 1) (to-save-jpg tmp-img tmp-layer (gen-fname fn start count ".jpg") interactive-save jpgcomp)) ((eqv? save-type 2) (to-save-png tmp-img tmp-layer (gen-fname fn start count ".png") interactive-save pngcomp))) (gimp-image-delete tmp-img) ;(gimp-display-delete tmp-display) ) (set! count (+ count 1)) ) ;; repeat until all layer is saved ) ) ;; ---------------------------------------- ;; register (script-fu-register "script-fu-continuous-save-trans-img-fill" "Continuous Save (m256) ..." "Save an Image by single layer with continuous number" "mieki256, Tamubun , Original: Iccii " "Iccii" "2008-07-28" "RGB* INDEXED* GRAY*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-DIRNAME "Save Dircetory" "" SF-STRING "Base File Name" "MyPicture_" SF-OPTION "Saved File Type" '("BMP" "JPG" "PNG") SF-ADJUSTMENT "JPEG Compression" '(75 0 100 1 5 0 0) SF-ADJUSTMENT "PNG Compression" '(9 1 9 1 1 0 0) SF-ADJUSTMENT "Digits" '(8 1 10 1 5 0 1) SF-ADJUSTMENT "Start Number" '(1 1 9999999 10 5 0 1) SF-TOGGLE "Reverse Order" FALSE SF-TOGGLE "Interactive" FALSE ) (script-fu-menu-register "script-fu-continuous-save-trans-img-fill" "/Script-Fu/Utils")