Guest User

save-selected.scm

a guest
Dec 5th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. ; This program is free software; you can redistribute it and/or modify
  2. ; it under the terms of the GNU General Public License as published by
  3. ; the Free Software Foundation; either version 2 of the License, or
  4. ; (at your option) any later version.
  5. ;
  6. ; This program is distributed in the hope that it will be useful,
  7. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. ; GNU General Public License for more details.
  10.  
  11. ;; Saves the selected region of an image to disk.
  12. ;; The file format is determined by the variable 'ext'
  13. ;; which is ".png" by default (change it below for other formats)
  14. ;;
  15. ;; The filename used consists of the original filename with a
  16. ;; a sequence count appended. The sequence count is "1" for the
  17. ;; first saved region, "2" for the second, and so on.
  18. ;;
  19. ;; If the the function is called with no selection then the sequence
  20. ;; number is reset back to "1" and subsequent saves will result in
  21. ;; the previous files being overwritten (this is a feature, not a bug)
  22. ;;
  23. ;; The command appears as "Save selected" under the File Menu.
  24.  
  25. (define (sg-save-selected image layer)
  26. (let* (
  27. (new-image 0)
  28. (buffer "")
  29. (fname "")
  30. (parasite 0)
  31. (index "0")
  32. (ext ".png")
  33. )
  34. (gimp-image-undo-disable image)
  35. (if (= (car (gimp-selection-bounds image)) FALSE)
  36. ;; If no selection then reset index count back to "1"
  37. (gimp-image-parasite-detach image "sg-index")
  38. (begin
  39. (set! index (catch "0"
  40. (set! parasite (gimp-image-parasite-find image "sg-index"))
  41. (caddr (car parasite)))
  42. )
  43. (set! index (number->string (+ (string->number index) 1)))
  44. (gimp-image-parasite-attach image (list "sg-index" 0 index))
  45. (set! buffer (car (gimp-edit-named-copy layer "temp-copy")))
  46. (set! new-image (car (gimp-edit-named-paste-as-new buffer)))
  47. (set! fname (car (gimp-image-get-filename image)))
  48. (when (= (string-length fname) 0)
  49. (set! fname (string-append "Untitled" ext))
  50. )
  51. (set! fname (strbreakup fname "."))
  52. (if (> (length fname) 1)
  53. (set! fname (string-append
  54. (unbreakupstr (butlast fname) ".") "-" index ext))
  55. (set! fname (string-append "Untitled-" index ext))
  56. )
  57. (gimp-file-save RUN-NONINTERACTIVE
  58. new-image
  59. (car (gimp-image-get-active-layer new-image))
  60. fname
  61. fname)
  62. (gimp-buffer-delete buffer)
  63. (gimp-image-delete new-image)
  64. )
  65. )
  66. (gimp-image-undo-enable image)
  67. (gimp-displays-flush)
  68. )
  69. )
  70.  
  71. (script-fu-register "sg-save-selected"
  72. "Сохранить выделенное"
  73. "Выделенное сохраняется в папку исходного файла (Если функция вызывается без выделения, то нумерация сбрасывается к %filename%-1, и последующее сохранение этого же файла приведёт к его перезаписи.)"
  74. "Saul Goode"
  75. "Saul Goode"
  76. "11/12/2008"
  77. "RGB*,GRAY*"
  78. SF-IMAGE "Image" 0
  79. SF-DRAWABLE "Drawable" 0
  80. )
  81.  
  82. (script-fu-menu-register "sg-save-selected"
  83. "<Image>/File"
  84. )
  85.  
Advertisement
Add Comment
Please, Sign In to add comment