Posted By

aprado on 10/27/09


Tagged

gimp script-fu


Versions (?)

GIMP Script-fu Cinematic Effect (cine-photo.scm)


 / Published in: Lisp
 

Make an image look like a movie

  1. ;
  2. ; cine-photo (2009)
  3. ;
  4. ; Adriano P. ([email protected])
  5. ;
  6. ; Create a cinematic effect
  7. ;
  8.  
  9. ;Duplicate layer
  10. (define (my-duplicate-layer image layer)
  11. (let*
  12. (
  13. (dup-layer (car (gimp-layer-copy layer 1)))
  14. )
  15. (gimp-image-add-layer image dup-layer 0)
  16. dup-layer
  17. ))
  18.  
  19. (define (script-fu-cine-photo inImage inLayer inCopy)
  20. (let*
  21. (
  22. (theDrawable 0)
  23. (theImage 0)
  24. (theLayer 0)
  25. (theWidth 0)
  26. (theHeight 0)
  27. (theBorder 50)
  28. )
  29. ;;START UNDO
  30. (gimp-image-undo-group-start inImage)
  31. (gimp-selection-all inImage)
  32. ;Duplicate image
  33. (set! theImage (if (= inCopy TRUE)
  34. (car (gimp-image-duplicate inImage))
  35. inImage)
  36. )
  37.  
  38. (set! theLayer (car (gimp-image-flatten theImage)))
  39. (set! theWidth (car (gimp-image-width theImage)))
  40. (set! theHeight (car (gimp-image-height theImage)))
  41. (set! theDrawable (car (gimp-image-get-active-drawable theImage)))
  42.  
  43. (gimp-hue-saturation theDrawable 0 0 0 -18)
  44. (gimp-curves-spline theDrawable 0 8 #(0 0 55 27 176 197 255 255))
  45.  
  46. ;Duplicate layer
  47. (set! theLayer (my-duplicate-layer theImage theLayer))
  48. (plug-in-gauss-rle RUN-NONINTERACTIVE theImage theLayer 5 TRUE TRUE)
  49.  
  50. ;Add layer mask
  51. (let
  52. (
  53. (shadow-mask (car (gimp-layer-create-mask theLayer ADD-WHITE-MASK)))
  54. )
  55. (gimp-layer-add-mask theLayer shadow-mask)
  56. )
  57.  
  58. ;Create new brush
  59. (let
  60. (
  61. (brushTemp (car (gimp-brush-new "Temp Brush")))
  62. (i 0)
  63. (xx (- theWidth (* 2 theBorder))) (yy (- theHeight (* 2 theBorder)))
  64. (mLayer (car (gimp-layer-new theImage theWidth theHeight
  65. RGBA-IMAGE "Black"
  66. 100 0)))
  67. )
  68. (gimp-brush-set-shape brushTemp BRUSH-GENERATED-CIRCLE)
  69. (gimp-brush-set-hardness brushTemp 0)
  70. (gimp-brush-set-radius brushTemp (/ theWidth 1.6))
  71. (gimp-brush-set-spacing brushTemp 20)
  72. (gimp-brush-set-spikes brushTemp 2)
  73. (gimp-brush-set-aspect-ratio brushTemp 1)
  74. (gimp-brush-set-angle brushTemp 0)
  75. (gimp-context-set-brush brushTemp)
  76. (gimp-context-set-paint-mode NORMAL-MODE)
  77.  
  78. (set! theDrawable (car (gimp-image-get-active-drawable theImage)))
  79.  
  80. ;Apply the brush
  81. (set! i 0)
  82. (while (< i 4)
  83. (set! i (+ i 1))
  84. (gimp-ellipse-select theImage
  85. (+ (rand (* i 10)) (/ theWidth 2)) (+ (rand (* i 10)) (/ theHeight 2))
  86. 1 1 REPLACE 0 0 0)
  87. (gimp-edit-stroke theDrawable)
  88. )
  89.  
  90. (gimp-image-add-layer theImage mLayer 0)
  91. (gimp-context-set-foreground '(0 0 0))
  92. (gimp-selection-all theImage)
  93. (gimp-edit-bucket-fill mLayer FG-BUCKET-FILL NORMAL-MODE 45 15 0 0 0)
  94. (gimp-selection-none theImage)
  95. ;Add layer mask
  96. (let
  97. (
  98. (shadow-mask (car (gimp-layer-create-mask mLayer ADD-WHITE-MASK)))
  99. )
  100. (gimp-layer-add-mask mLayer shadow-mask)
  101. )
  102.  
  103. (set! theDrawable (car (gimp-image-get-active-drawable theImage)))
  104.  
  105. ;Apply the brush
  106. (set! i 0)
  107. (while (< i 20)
  108. (set! i (+ i 1))
  109. (gimp-ellipse-select theImage
  110. (+ theBorder (rand xx)) (+ theBorder (rand yy))
  111. 1 1 REPLACE 0 0 0)
  112. (gimp-edit-stroke theDrawable)
  113. )
  114. ) ;end of let
  115.  
  116. (set! theLayer (car (gimp-image-flatten theImage)))
  117. (if (= inCopy TRUE)
  118. (begin
  119. (gimp-image-clean-all theImage)
  120. (gimp-display-new theImage)
  121. )
  122. )
  123. (gimp-selection-none inImage)
  124. ;;END UNDO
  125. (gimp-image-undo-group-end inImage)
  126. (gimp-displays-flush theImage)
  127. ))
  128.  
  129. (script-fu-register "script-fu-cine-photo"
  130. _"_Cine Photo..."
  131. _"Adds a cinematic effect"
  132. "Adriano Prado"
  133. "2009"
  134. "2009-11-03"
  135. "RGB* GRAY*"
  136. SF-IMAGE "The image" 0
  137. SF-DRAWABLE "The layer" 0
  138. SF-TOGGLE _"Work on copy" TRUE
  139. )
  140.  
  141. (script-fu-menu-register "script-fu-cine-photo"
  142. "<Image>/Filters/Decor")

Report this snippet  

You need to login to post a comment.