Advertisement
Guest User

Gimp Panel-Merger Script-Fu

a guest
Mar 29th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 3.13 KB | None | 0 0
  1. ; A simple script to merge seperated panels of a vertical comic.
  2. ; Install this script by copy pasting its contents into notepad, saving as panel-merger.scm,
  3. ; and putting it into GIMPs script folder (which is usually found at C\Program Files\GIMP x.x\share\gimp\x.x\scripts).
  4. ; Then restart GIMP or click Filters > Script-Fu > Refresh Scripts.
  5. ; Simply add the image of each panel of the comic to GIMP such that the 1st panel is at the top of the layer list
  6. ; and the last panel is at the bottom, then run this script by navigating to Image > Merge Panels, and you're done!
  7.  
  8. ; Works best when panels are all of same height and width. Doesn't (usually) explode if they're not,
  9. ; just might require some manual canvas resizing or layer offsetting to fix it up.
  10.  
  11.  
  12. (define (script-fu-panel-merger imagevariable)
  13. (let*   ( ;declare ALL the variables!
  14.     (layercount (car (gimp-image-get-layers imagevariable)))
  15.     (templayercount 0)
  16.     (behindtlc 0)
  17.     (layerlist (cadr (gimp-image-get-layers imagevariable)))
  18.     (heightlist (cadr (gimp-image-get-layers imagevariable)))
  19.     (tempheightvalue 0)
  20.     (lastlayerheight 0)
  21.     (lastlayercount 0)
  22.     (canvaswidth (car (gimp-image-width imagevariable)))
  23.     )
  24.  
  25. (gimp-undo-push-group-start imagevariable)  ;sets where to revert to when you hit the undo button
  26.  
  27. (while (< templayercount layercount) ;gets height value to resize canvas to, and populates vector with list of layer heights for later
  28.     (set! tempheightvalue (+ tempheightvalue (car (gimp-drawable-height (vector-ref layerlist templayercount)))))
  29.     (vector-set! heightlist templayercount (gimp-drawable-height (vector-ref layerlist templayercount)))
  30.     (set! templayercount (+ templayercount 1))
  31. )
  32.     (gimp-image-resize imagevariable canvaswidth tempheightvalue 0 0)   ;resizes the canvas to combined height of layers
  33.  
  34. (set! templayercount 0)
  35. (while (< templayercount layercount)    ;adds alpha channels to each layer
  36.     (gimp-layer-add-alpha (vector-ref layerlist templayercount))
  37.     (set! templayercount (+ templayercount 1))
  38. )
  39.  
  40. (set! templayercount 0)
  41. (while (< templayercount layercount)    ;resizes each layer to canvas size
  42.     (gimp-layer-resize-to-image-size (vector-ref layerlist templayercount))
  43.     (set! templayercount (+ templayercount 1))
  44. )
  45.  
  46. (set! templayercount 1)
  47. (if (> layercount 1)
  48.     (while (< templayercount layercount)    ;offsets each layer by the appropiate height
  49.         (set! lastlayerheight (+ lastlayerheight (car (vector-ref heightlist behindtlc))))
  50.         (gimp-layer-set-offsets (vector-ref layerlist templayercount) 0 lastlayerheight)
  51.         (set! templayercount (+ templayercount 1))
  52.         (set! behindtlc (+ behindtlc 1))
  53.     )
  54. )
  55.  
  56. (gimp-undo-push-group-end imagevariable)
  57. (gimp-displays-flush)
  58.  
  59. );paren let*
  60. );paren define
  61.  
  62.     (script-fu-register
  63.     "script-fu-panel-merger"
  64.     "Merge Panels"
  65.     "Merges panels of a comic vertically: \
  66.     first arrange each panel as a layer,\
  67.     with the first panel as the first layer,\
  68.     and so on, before running the script."
  69.     "Anon"
  70.     "No restrictions on use/modfication."
  71.     "March 29th, 2017"
  72.     ""
  73.     SF-IMAGE    "SF-IMAGE" 0
  74.     )
  75.     (script-fu-menu-register "script-fu-panel-merger" "<Image>/Image") ;puts "Merge Panels" under the Image menu in GIMP GUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement