PDA

Vollständige Version anzeigen : [Script] Copy Image 2 Image


flashnfantasy
10.03.2008, 14:15
Das Script leistet folgendes:
- Erzeugen eines neuen Bildes aus dem aktuellen Bild oder einer Auswahl davon
- Kopieren des Bildes oder einer Auswahl davon, und da gibt es folgende weitere Optionen:
--- ganz normal über das Zielbild
--- rechts an das Bild ranhängen, und die Größe des Bildes dabei anpassen, so daß die beiden Bilder nahtlos sind (siehe Beispiel unten)
--- unter das Zielbild, da ebenfalls an die Größe anpassen
--- über das Zielbild (über meint jetzt als eigene Ebene), und das Bild dabei dem Zielbild anpassen
--- über das Zielbild mit einer festen Größe
- desweiteren gibt es für das gewählte Bild folgende Optionen:
--- nur die aktuelle Ebene
--- alle als sichtbar gekennzeichneten Ebenen übereinander
--- alle als sichtbar gekennzeichneten Ebenen nebeneinander (von links nach rechts)

Nicht alle Kombinationen machen Sinn !

8562

(define (copysel img drawable copy-img copy-how copy-what fix-scaled desaturates)

(gimp-undo-push-group-start img)
(if (= img copy-img) (set! copy-how 0))
(define selection-bounds (gimp-selection-bounds img))
(define select-offset-x (cadr selection-bounds))
(define select-offset-y (caddr selection-bounds))
(define selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
(define selection-height (- (caddr (cddr selection-bounds)) select-offset-y))

(define draw-type (car (gimp-drawable-type-with-alpha drawable)))
(define image-type (car (gimp-image-base-type img)))
(define new-image copy-img)
(if (= 0 copy-how)
(begin
(define new-image (car (gimp-image-new selection-width selection-height image-type)))
(define display-work (car (gimp-display-new new-image)))
))
(gimp-undo-push-group-start new-image)
(define img_width (car (gimp-image-width new-image)))
(define img_height (car (gimp-image-height new-image)))

(define old_width (car (gimp-image-width img)))
(define old_height (car (gimp-image-height img)))

(define layers (gimp-image-get-layers img))
(define num-of-layers (car layers))
(define index num-of-layers)

(define descr "")

(define layers-list (cadr layers))
(define layer)
(define make-a-copy)
(define layer-vis)
(define offs-x)
(define offs-y)
(define size-x)
(define size-y)
(define offsmx)
(define offsmy)
(define sizemx)
(define sizemy)
(define new_width)
(define new_height)
(define scale)
(define scaleX)
(define scaleY)
(define layer-mode)
(define new-draw)
(define floating-sel)
(define halfx)
(define halfy)
(while (< 0 index)
(set! index (- index 1))
(set! layer (aref layers-list index))
(set! make-a-copy 1)
(if (and (= copy-what 0) (not (= layer drawable)))
(set! make-a-copy 0)
)

(set! layer-vis (car (gimp-drawable-get-visible layer)))

(if (= layer-vis FALSE)
(set! make-a-copy 0)
)

(if (= make-a-copy 1)
(begin
(gimp-selection-none img)
(gimp-selection-clear img)
(gimp-layer-set-preserve-trans layer TRUE)
(gimp-selection-all img)
(set! offs-x (car (gimp-drawable-offsets layer)))
(set! offs-y (cadr (gimp-drawable-offsets layer)))
(set! size-x (car (gimp-drawable-width layer)))
(set! size-y (car (gimp-drawable-height layer)))

(set! descr (string-append descr "Offs: "))
(set! descr (string-append descr (number->string offs-x)))
(set! descr (string-append descr ", "))
(set! descr (string-append descr (number->string offs-y)))
(set! descr (string-append descr "\n"))
(set! descr (string-append descr "Image Dim (orign): "))
(set! descr (string-append descr (number->string size-x)))
(set! descr (string-append descr ", "))
(set! descr (string-append descr (number->string size-y)))
(set! descr (string-append descr "\n"))

; berechnen des tatsächlich kopierten Ausschnittes
(set! offsmx offs-x)
(if (< offsmx 0) (set! offsmx 0))
(set! sizemx (+ size-x offs-x))
(if (< old_width sizemx) (set! sizemx old_width))
(set! sizemx (- sizemx offsmx))

(set! offsmy offs-y)
(if (< offsmy 0) (set! offsmy 0))
(set! sizemy (+ size-y offs-y))
(if (< old_height sizemy) (set! sizemy old_height))
(set! sizemy (- sizemy offsmy))

(gimp-edit-copy layer)
(set! new_width selection-width)
(set! new_height selection-height)
(if (= copy-what 2)
(begin
(set! img_width (car (gimp-image-width new-image)))
(set! img_height (car (gimp-image-height new-image)))
))

(set! scaleX (/ img_width new_width))
(set! scaleY (/ img_height new_height))

(set! descr (string-append descr "Image Dim (target): "))
(set! descr (string-append descr (number->string img_width)))
(set! descr (string-append descr ", "))
(set! descr (string-append descr (number->string img_height)))
(set! descr (string-append descr "\n"))

(set! layer-mode (car (gimp-layer-get-mode layer)))

(set! new-draw (car (gimp-layer-new new-image (car (gimp-image-width img)) (car (gimp-image-height img)) draw-type "Selection" 100 layer-mode)))
(gimp-image-add-layer new-image new-draw 0)

(gimp-selection-none new-image)
(gimp-drawable-fill new-draw 3)
(gimp-edit-clear new-draw)
(gimp-selection-clear new-image)
(set! floating-sel (car (gimp-edit-paste new-draw FALSE)))
(gimp-floating-sel-anchor floating-sel)

(set! halfx (/ (- old_width sizemx) 2))
(set! halfy (/ (- old_height sizemy) 2))


(set! descr (string-append descr "half: "))
(set! descr (string-append descr (number->string halfx)))
(set! descr (string-append descr ", "))
(set! descr (string-append descr (number->string halfy)))
(set! descr (string-append descr "\n"))
(set! descr (string-append descr "offs: "))
(set! descr (string-append descr (number->string offsmx)))
(set! descr (string-append descr ", "))
(set! descr (string-append descr (number->string offsmy)))
(set! descr (string-append descr "\n"))
(set! descr (string-append descr "select-offset: "))
(set! descr (string-append descr (number->string select-offset-x)))
(set! descr (string-append descr ", "))
(set! descr (string-append descr (number->string select-offset-y)))
(set! descr (string-append descr "\n"))
(set! descr (string-append descr "select-width: "))
(set! descr (string-append descr (number->string selection-width)))
(set! descr (string-append descr ", "))
(set! descr (string-append descr (number->string selection-height)))
(set! descr (string-append descr "\n"))
(set! descr (string-append descr "copy-how: "))
(set! descr (string-append descr (number->string copy-how)))
(set! descr (string-append descr "\n"))

(gimp-layer-set-offsets new-draw (- (- offsmx halfx) select-offset-x) (- (- offsmy halfy) select-offset-y))

(gimp-layer-resize new-draw selection-width selection-height (- (- offsmx halfx) select-offset-x) (- (- offsmy halfy) select-offset-y))
;(gimp-layer-resize new-draw sizemx sizemy (- (- 0 halfx) select-offset-x) (- (- 0 halfy) select-offset-y))

(if (= copy-how 1)
(begin
(gimp-layer-scale new-draw (* new_width scaleY) (* new_height scaleY) TRUE)
(gimp-layer-set-offsets new-draw img_width 0)
(gimp-image-resize new-image (+ img_width (* new_width scaleY)) img_height 0 0)
))
(if (= copy-how 2)
(begin
(gimp-layer-scale new-draw (* new_width scaleX) (* new_height scaleX) TRUE)
(gimp-layer-set-offsets new-draw 0 img_height)
(gimp-image-resize new-image img_width (+ img_height (* new_height scaleX)) 0 0)
))
(if (= copy-how 3)
(begin
(gimp-layer-set-offsets new-draw img_width 0)
(gimp-image-resize new-image (+ img_width new_width) img_height 0 0)
))
(if (= copy-how 4)
; do nothing
)
(if (= copy-how 5)
(begin
(set! scale (min (/ fix-scaled selection-width) (/ fix-scaled selection-height)))
(gimp-layer-scale new-draw (* new_width scale) (* new_height scale) TRUE)
;(- (- offsmx halfx) select-offset-x) (- (- offsmy halfy) select-offset-y)
(if (= desaturates TRUE)
(begin
(gimp-desaturate-full new-draw 1)
(plug-in-c-astretch 0 img new-draw)
))
(gimp-layer-set-offsets new-draw 0 0)
))
(if (= copy-how 0)
; Macht aus mehreren Ebenen eine neue Bildstrecke
(if (= 2 copy-what) (set! copy-how 1))
)

(gimp-drawable-set-visible new-draw layer-vis)
(gimp-layer-set-name new-draw descr)
))
)

(gimp-rect-select img select-offset-x select-offset-y selection-width selection-height 2 0 0)
(gimp-displays-flush)
(gimp-image-clean-all img)
(gimp-image-undo-group-end img)
(gimp-image-undo-group-end new-image)

)

(script-fu-register "copysel"
"<Image>/Script-Fu/Selection/To Image Improved"
"Kopiert alle Ebenen in ein neues Image oder haengt es an ein anderes Image an. Soll vorallem das Zusammenfuegen von Bildern erleichtern. Wird ein Bereich aus dem Sourceimage ausgewaehlt, so wird der umfassende rechteckige Bereich verarbeitet. P1: Sourceimage, P2: Layer, nur interessant, wenn p5 auf 0 steht, P3: Targetimage, nur von interesse, wenn p4 groesser 0, P4: Methode, mit der das Sourceimage an das Targetimage angehaengt werden kann - 0=neues Image, 1=rechts an das Image, Feld wird skaliert, 2=unter das Image, Feld wird skaliert, 4=ueber das Image, unskaliert, ist sinnvoll, wenn Elemente von einem Image in ein Anderes kopiert werden sollen."
"Mathias"
"Mathias"
"25/02/08 (absolute Alpha-Version)"
"RGB*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Layer" 0
SF-IMAGE _"To Image" 0
SF-OPTION _"new Image" '(_"new image"
_"right of image, scaled"
_"below of image, scaled"
_"right of image, unscaled"
_"over image"
_"over image, fix scaled"
)
SF-OPTION _"copy what" '(_"layer only"
_"all visible layers stacked"
_"all visible layers spread"
)
SF-ADJUSTMENT _"fix scaled" '(400 100 1000 1 1 1 0)
SF-TOGGLE _"fix scaled desaturate" FALSE
)