Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; 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.
- ;; Saves the selected region of an image to disk.
- ;; The file format is determined by the variable 'ext'
- ;; which is ".png" by default (change it below for other formats)
- ;;
- ;; The filename used consists of the original filename with a
- ;; a sequence count appended. The sequence count is "1" for the
- ;; first saved region, "2" for the second, and so on.
- ;;
- ;; If the the function is called with no selection then the sequence
- ;; number is reset back to "1" and subsequent saves will result in
- ;; the previous files being overwritten (this is a feature, not a bug)
- ;;
- ;; The command appears as "Save selected" under the File Menu.
- (define (sg-save-selected image layer)
- (let* (
- (new-image 0)
- (buffer "")
- (fname "")
- (parasite 0)
- (index "0")
- (ext ".png")
- )
- (gimp-image-undo-disable image)
- (if (= (car (gimp-selection-bounds image)) FALSE)
- ;; If no selection then reset index count back to "1"
- (gimp-image-parasite-detach image "sg-index")
- (begin
- (set! index (catch "0"
- (set! parasite (gimp-image-parasite-find image "sg-index"))
- (caddr (car parasite)))
- )
- (set! index (number->string (+ (string->number index) 1)))
- (gimp-image-parasite-attach image (list "sg-index" 0 index))
- (set! buffer (car (gimp-edit-named-copy layer "temp-copy")))
- (set! new-image (car (gimp-edit-named-paste-as-new buffer)))
- (set! fname (car (gimp-image-get-filename image)))
- (when (= (string-length fname) 0)
- (set! fname (string-append "Untitled" ext))
- )
- (set! fname (strbreakup fname "."))
- (if (> (length fname) 1)
- (set! fname (string-append
- (unbreakupstr (butlast fname) ".") "-" index ext))
- (set! fname (string-append "Untitled-" index ext))
- )
- (gimp-file-save RUN-NONINTERACTIVE
- new-image
- (car (gimp-image-get-active-layer new-image))
- fname
- fname)
- (gimp-buffer-delete buffer)
- (gimp-image-delete new-image)
- )
- )
- (gimp-image-undo-enable image)
- (gimp-displays-flush)
- )
- )
- (script-fu-register "sg-save-selected"
- "Сохранить выделенное"
- "Выделенное сохраняется в папку исходного файла (Если функция вызывается без выделения, то нумерация сбрасывается к %filename%-1, и последующее сохранение этого же файла приведёт к его перезаписи.)"
- "Saul Goode"
- "Saul Goode"
- "11/12/2008"
- "RGB*,GRAY*"
- SF-IMAGE "Image" 0
- SF-DRAWABLE "Drawable" 0
- )
- (script-fu-menu-register "sg-save-selected"
- "<Image>/File"
- )
Advertisement
Add Comment
Please, Sign In to add comment