11 hours ago
Hello!
I have trouble with porting a script written in Script-Fu from Gimp2 to Gimp3. I managed to run the script, but when script execution finished, I've got the following error: argument 1 must be: number. Unfortunately, I cannot understand why this error occurs. Could anyone review my code and help me to make the script working. The script is below:
I have trouble with porting a script written in Script-Fu from Gimp2 to Gimp3. I managed to run the script, but when script execution finished, I've got the following error: argument 1 must be: number. Unfortunately, I cannot understand why this error occurs. Could anyone review my code and help me to make the script working. The script is below:
Code:
#!/usr/bin/env gimp-script-fu-interpreter-3.0
; Adds labels to a layer
; Works with Gimp v.3
(define (script-fu-add-labels image drawables user-text font font-size
font-color x y outline-toggle outline-color
outline-thickness)
(let* ((current-layer (vector-ref drawables 0))
(off-x (car (gimp-drawable-get-offsets current-layer)))
(off-y (cadr (gimp-drawable-get-offsets current-layer)))
(text-layer)
(text-layer-position-x (+ off-x x))
(text-layer-position-y (+ off-y y))
(text-layer-outline)
(text-layer-vectors)
(text-layer-group)
(text-layer-group-name)
(text-foreground-color-old)
(parent-layer-type 0)
(parent-layer-name)
(parent-layer-group (car (gimp-item-get-parent current-layer)))
(old-background (car (gimp-context-get-background))))
(cond ((= #t (car (gimp-item-id-is-channel current-layer))) (set! layer-type 1))
((= #t (car (gimp-item-is-group current-layer))) (set! layer-type 1))
((= #t (car (gimp-item-id-is-layer-mask current-layer))) (set! layer-type 1))
((= #t (car (gimp-item-id-is-selection current-layer))) (set! layer-type 1))
((= #t (car (gimp-item-id-is-text-layer current-layer))) (set! layer-type 1)))
(gimp-image-undo-group-start image)
(if (= 1 parent-layer-type)
(begin
(set! parent-layer-name (car (gimp-item-get-name current-layer)))
(gimp-message
(string-append "Cannont add the label to the layer " parent-layer-name)))
(begin
(set! text-layer (car (gimp-text-font image -1 text-layer-position-x
text-layer-position-y user-text 2 #t
font-size POINTS font)))
(gimp-text-layer-set-color text-layer font-color)
(when (= outline-toggle #t)
(set! text-layer-group (car (gimp-layer-group-new image)))
(set! text-layer-group-name
(string-append "Text_" (car (gimp-text-layer-get-text
text-layer))))
(set! text-layer-vectors (car (gimp-vectors-new-from-text-layer image
text-layer)))
(set! text-layer-outline (car (gimp-layer-copy text-layer #t)))
(set! text-foreground-color-old (car (gimp-context-get-foreground)))
(gimp-item-set-name text-layer-group text-layer-group-name)
(gimp-image-insert-layer image text-layer-group 0 0)
(gimp-image-insert-vectors image text-layer-vectors 0 -1)
(gimp-image-reorder-item image text-layer text-layer-group 0)
(gimp-image-insert-layer image text-layer-outline text-layer-group -1)
(gimp-context-set-foreground outline-color)
(gimp-context-set-stroke-method 0)
(gimp-context-set-line-width outline-thickness)
(gimp-drawable-edit-stroke-item text-layer-outline text-layer-vectors)
(gimp-context-set-foreground text-foreground-color-old)
(gimp-item-set-expanded text-layer-group #f)
(gimp-item-set-lock-position text-layer-outline #t))
(gimp-item-set-lock-position text-layer #t)))
(gimp-displays-flush)
(gimp-image-undo-group-end image)))
(script-fu-register-filter "script-fu-add-labels"
_"Add labels"
_""
""
""
""
"*"
SF-ONE-OR-MORE-DRAWABLE
SF-STRING _"Label" "A"
SF-FONT _"Font" "Arial Bold"
SF-ADJUSTMENT _"Font size" (list 50 5 100 1 10 0 1)
SF-COLOR _"Font color" (list 0 0 0)
SF-ADJUSTMENT _"Offset X" (list 6 0 500 1 10 0 1)
SF-ADJUSTMENT _"Offset Y" (list 6 0 500 1 10 0 1)
SF-TOGGLE _"Outline" #f
SF-COLOR _"Outline color" (list 255 255 255)
SF-ADJUSTMENT _"Outline thickness" (list 1 0 5 1 1 0 1)
)
(script-fu-menu-register "script-fu-add-labels"
"<Image>/Figures")