In the first part of the article, we reviewed the “Fast Shadow” and “Crop Corners” scripts and promised to show how beautifully to draw a screenshot of a window fragment. It's time to fulfill the promise. Today we will analyze the script “Framing with Wave Effect”, which allows you to cut off part of the image along wavy lines that look like sinusoids.
(define (script-fu-wave-crop image drawable ampl-factor reverse-phase) (gimp-context-push) (gimp-image-set-active-layer image drawable) (gimp-image-undo-group-start image) ; (if (= (car (gimp-selection-bounds image)) FALSE) (gimp-message " , .") (let* ( ; (selection-box (cdr (gimp-selection-bounds image))) ; (x1 (car selection-box)) (y1 (cadr selection-box)) ; (x2 (caddr selection-box)) (y2 (cadddr selection-box)) ; (image-width (car (gimp-image-width image))) (image-height (car (gimp-image-height image))) ) ; , (if (and (= x1 0) (= y1 0) (= x2 image-width) (= y2 image-height)) (gimp-message " , .") (let* ( ; gimp-free-select. ; 2 (x y ) (points (cons-array (* (+ (* 2 (- x2 x1)) (* 2 (- y2 y1))) 2) 'double)) (i 0) ; , (ampl-x (* (- y2 y1) ampl-factor 0.005)) (ampl-y (* (- x2 x1) ampl-factor 0.005)) ; " " (2pi 6.2832) (x x1) (y y1) ) ; (if (= reverse-phase TRUE) (begin ; (set! ampl-x (- ampl-x)) (set! ampl-y (- ampl-y)) ) ) ; (while (< x x2) (aset points ix) ; ; , (if (> y1 0) ; , (aset points (+ i 1) (+ y1 (* ampl-y (sin (* 2pi (/ (- x x1) (- x2 x1))))))) ; - . (aset points (+ i 1) 0) ) (set! i (+ i 2)) (set! x (+ x 1)) ) ; (while (< y y2) ; ; , (if (< x2 image-width) ; , (aset points i (+ x2 (* ampl-x (sin (- (* 2pi (/ (- y y1) (- y2 y1)))))))) ; - . (aset points i image-width) ) (aset points (+ i 1) y) (set! i (+ i 2)) (set! y (+ y 1)) ) ; (while (> x x1) (aset points ix) ; ; , (if (< y2 image-height) ; , (aset points (+ i 1) (+ y2 (* ampl-y (sin (* 2pi (/ (- x x1) (- x2 x1))))))) ; - . (aset points (+ i 1) image-height) ) (set! i (+ i 2)) (set! x (- x 1)) ) ; (while (> y y1) ; ; , (if (> x1 0) ; , (aset points i (+ x1 (* ampl-x (sin (- (* 2pi (/ (- y y1) (- y2 y1)))))))) ; - . (aset points i 0) ) (aset points (+ i 1) y) (set! i (+ i 2)) (set! y (- y 1)) ) ; (gimp-free-select image i points CHANNEL-OP-REPLACE TRUE FALSE 0) ; (gimp-selection-invert image) ; (gimp-layer-add-alpha drawable) ; (gimp-edit-clear drawable) ; (gimp-selection-none image) ; (plug-in-autocrop 1 image drawable) ) ) ) ) (gimp-image-undo-group-end image) (gimp-displays-flush) (gimp-context-pop) ) (script-fu-register "script-fu-wave-crop" " " " ." " <pupkin@example.com>" " " "2010/10/28" "RGB* GRAY*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-ADJUSTMENT " (0 - , 10 - )" '(3 0 10 1 0 0) SF-TOGGLE " " FALSE ) (script-fu-menu-register "script-fu-wave-crop" "<Image>/Filters/ ") 

(define (script-fu-screenshot-processing image drawable cut-corners radius only-top ampl-factor reverse-phase) (gimp-context-push) (gimp-image-set-active-layer image drawable) (gimp-image-undo-group-start image) (let* ( (selection-channel nil) ; , (cropping-required (car (gimp-selection-bounds image))) ) ; , (if (= cut-corners TRUE) (begin ; (set! selection-channel (car (gimp-selection-save image))) (script-fu-cut-corners image drawable radius only-top) ) ) ; , (if (= cropping-required TRUE) (begin ; (if (= cut-corners TRUE) (gimp-selection-load selection-channel)) (script-fu-wave-crop image drawable ampl-factor reverse-phase) ) ) ; script-fu-quick-shadow (script-fu-quick-shadow image drawable) ) (gimp-image-undo-group-end image) (gimp-displays-flush) (gimp-context-pop) ) (script-fu-register "script-fu-screenshot-processing" " " " , ." " <pupkin@example.com>" " " "2010/10/28" "RGB* GRAY*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-TOGGLE " " TRUE SF-ADJUSTMENT " (0 - 20 )" '(8 0 20 1 10 0 0) SF-TOGGLE " " FALSE SF-ADJUSTMENT " (0 - , 10 - )" '(3 0 10 1 0 0) SF-TOGGLE " " FALSE ) (script-fu-menu-register "script-fu-screenshot-processing" "<Image>/Filters/ ") 

Source: https://habr.com/ru/post/107026/
All Articles