GIMP Script-fu

Artifact [77a1c930f5]
Login

Artifact 77a1c930f561a9c6798e8049c4b8ee32adfe8aac:


; 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.

(define (sg-alpha-to-svg-file image drawable constraint svg-file)
  (define (get-real-layers image . fundament)
    (let ((fundament (if (pair? fundament)
                       (car fundament)
                       #f )))
      (let loop ((children (vector->list (cadr (if fundament
                                                 (gimp-item-get-children fundament)
                                                 (gimp-image-get-layers image) ))))
                 (layers '()) )
        (if (null? children)
          layers
          (loop (cdr children)
                (if (= TRUE (car (gimp-item-is-group (car children))))
                  (append layers (get-real-layers image (car children)))
                  (append layers (list (car children))) ))))))
  (gimp-image-undo-group-start image)
	(let loop ((layers (reverse
	                     (case constraint
	                        ((0) ; all layers
	                          (get-real-layers image) )
	                       ((1) ; visibles
	                         (let loop ((layers (get-real-layers image))
	                                    (visibles '()) )
	                           (if (null? layers)
	                             (reverse visibles)
	                             (loop (cdr layers)
	                                   (if (= TRUE (car (gimp-item-get-visible (car layers))))
	                                     (cons (car layers) visibles)
	                                     visibles )))))
	                       ((2) ; linked
	                         (let loop ((layers (get-real-layers image))
	                                    (linkeds '()) )
	                           (if (null? layers)
	                             (reverse linkeds)
	                             (loop (cdr layers)
	                                   (if (= TRUE (car (gimp-item-get-linked (car layers))))
	                                     (cons (car layers) linkeds)
	                                     visibles )))))
	                       ((3) ; active
	                         (list drawable) )))))
    (unless (null? layers)
      (let* ((layer (car layers))
             (name (car (gimp-item-get-name layer))) )
        (gimp-image-select-item image CHANNEL-OP-REPLACE layer)
        (plug-in-sel2path-advanced RUN-NONINTERACTIVE 
                                   image
                                   layer
                                   0.50    ; align-threshold
                                   60.00   ; corner-always-threshold
                                   4       ; corner-surround
                                   100.00  ; corner-threshold
                                   0.40    ; error-threshold
                                   1       ; filter-alternative-surround
                                   10.00   ; filter-epsilon
                                   4       ; filter-iteration-count
                                   0.33    ; filter-percent
                                   3       ; filter-secondary-surround
                                   2       ; filter-surround
                                   TRUE    ; keep-knees
                                   0.010   ; line-reversion-threshold
                                   0.50    ; line-threshold
                                   0.01    ; reparameterize-improvement
                                   1.00    ; reparameterize-threshold
                                   0.10    ; subdivide-search
                                   4       ; subdivide-surround
                                   0.03    ; subdivide-threshold
                                   3       ; tangent-surround
                                   )
        (gimp-item-set-name (car (gimp-image-get-active-vectors image)) name)
        (loop (cdr layers)) )))

  (gimp-vectors-export-to-file image
                               svg-file 
                               0 )
  (gimp-image-undo-group-end image)
  )

 (script-fu-register "sg-alpha-to-svg-file"
  "Save alpha to SVG..."
  "Save alpha to SVG using layer names as filenames"
  "Saul Goode"
  "Saul Goode"
  "January 2014"
  "RGB* GRAY*"
  SF-IMAGE "Image" 0
  SF-DRAWABLE "Drawable" 0
  SF-OPTION "Layers" '("All layers" "Visible layers" "Linked layers" "Active layer")
  SF-FILENAME "File name" ""
  )

(script-fu-menu-register "sg-alpha-to-svg-file"
  "<Image>/Filters/Misc/" )