This file is indexed.

/usr/share/gimp/2.0/scripts/theuncle2k-cut-layers-out-of-boundaries.scm is in gimp-plugin-registry 7.20140602+b4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
;
;
; The GIMP -- an image manipulation program
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
;
; Cut layers out of boundaries for GIMP 2.6
; Original author: TheUncle2k
;
; Tags: cut, crop
;
; Author statement:
;
; Cuts any portion of the active
; layer placed out of the image boundaries. The action
; can also be performed on all the available layers at once.
; If the layer is completely out of the image, it will be deleted.
;
; --------------------------------------------------------------------
; Distributed by Gimp FX Foundry project
; --------------------------------------------------------------------
;   - Changelog -
;
; --------------------------------------------------------------------
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(script-fu-register
     "script-fu-cut-layers-out-of-boundaries"
    _"Cut layers out of boundaries..."
    _"Cut the portion of the active layer or of all layers that are outside of the image boundaries"
     "TheUncle2k"
     "copyright 2009, TheUncle2k / http://theuncle2k.deviantart.com"
     "21st December 2009"
     ""
     SF-IMAGE     "Input Image"    0
     SF-DRAWABLE  "Input Layer"    0
     SF-TOGGLE   _"Cut all"        FALSE
    )
    (script-fu-menu-register "script-fu-cut-layers-out-of-boundaries" _"<Image>/FX-Foundry/Layer Effects")


(define (script-fu-cut-layers-out-of-boundaries inImg inDrawable inCutAll)

    (let* (
        (theImgWidth (car (gimp-image-width inImg)))
        (theImgHeight (car (gimp-image-height inImg)))
        (theIterations 0)
        (theLayerNum 1)
        (theWorkingLayer 0)
        (theLayerWidth 0)
        (theLayerHeight 0)
        (theLayerOffsetX 0)
        (theLayerOffsetY 0)
        (theOutRight 0)
        (theOutDown 0)
        (theDeleted 0)
    )

    ;begin undo group

    (gimp-image-undo-group-start inImg)

    (set! theWorkingLayer inDrawable)

    ;verify if cycling through all layers is needed

    (if (equal? inCutAll TRUE)

        ;save how many layers are available

        (set! theLayerNum (car(gimp-image-get-layers inImg)))
    )


    (while (< theIterations theLayerNum)


        ;if working on all layers, set the next layer available, starting from the first
        ;in the stack

        (if (equal? inCutAll TRUE)
            (begin
                (set! theWorkingLayer (aref (cadr (gimp-image-get-layers inImg)) theIterations))
                (gimp-image-set-active-layer inImg theWorkingLayer)
            )
        )


        ;save the position and dimensions of the layer

        (set! theLayerOffsetX (car(gimp-drawable-offsets theWorkingLayer)))
        (set! theLayerOffsetY (cadr(gimp-drawable-offsets theWorkingLayer)))
        (set! theLayerWidth (car(gimp-drawable-width theWorkingLayer)))
        (set! theLayerHeight (car(gimp-drawable-height theWorkingLayer)))


        ;check if the layer is out of the right boundary and save the amount

        (if (> (+ theLayerWidth theLayerOffsetX) theImgWidth)
                (set! theOutRight (- (+ theLayerWidth theLayerOffsetX) theImgWidth))
        )


        ;check if the layer is out of the bottom boundary and save the amount

        (if (> (+ theLayerHeight theLayerOffsetY) theImgHeight)
            (set! theOutDown (- (+ theLayerHeight theLayerOffsetY) theImgHeight))
        )


        ;if the layer is completely out of the left boundary delete it
        
        (cond ((< theLayerOffsetX (- (- theLayerWidth 1)))
              (begin
                (gimp-image-remove-layer inImg theWorkingLayer)
                (set! theDeleted 1)
              );end begin
              )
              ((< theLayerOffsetX 0)
              (begin

                ;resize the layer to fit the left boundary of the image.

                (gimp-layer-resize theWorkingLayer
                           (- theLayerWidth (- theLayerOffsetX))
                           theLayerHeight
                           theLayerOffsetX
                           0)

                ;update the dimensions of the layer

                (set! theLayerWidth (car (gimp-drawable-width theWorkingLayer)))
                (set! theLayerHeight (car (gimp-drawable-height theWorkingLayer)))
            );end begin
            )
        );end cond

        ;work on the layer if it has not been already deleted

        (if (= theDeleted 0)

        ;if the layer is completely out of the top boundary delete it

        (cond ((< theLayerOffsetY (- (- theLayerHeight 1)))
            (begin
                (gimp-image-remove-layer inImg theWorkingLayer)
                (set! theDeleted 1)
            );end begin
              )
              ((< theLayerOffsetY 0)
            (begin

                ;resize the layer to fit the top boundary of the image.

                (gimp-layer-resize theWorkingLayer
                           theLayerWidth
                           (- theLayerHeight (- theLayerOffsetY))
                           0
                           theLayerOffsetY)

                ;update the dimensions of the layer

                (set! theLayerWidth (car (gimp-drawable-width theWorkingLayer)))
                (set! theLayerHeight (car (gimp-drawable-height theWorkingLayer)))
            );end begin
            )
        );end cond
        );end if

        ;work on the layer if it has not been already deleted

        (if (= theDeleted 0)

        ;if the layer is completely out of the right boundary delete it

        (cond ((> theOutRight (- theLayerWidth 1))
            (begin
                (gimp-image-remove-layer inImg theWorkingLayer)
                (set! theDeleted 1)
            );end begin
              )
              ((> theOutRight 0)
            (begin

                ;resize the layer to fit the right boundary of the image.

                (gimp-layer-resize theWorkingLayer
                           (- theLayerWidth theOutRight)
                           theLayerHeight
                           0
                           0)

                ;update the dimensions of the layer

                (set! theLayerWidth (car(gimp-drawable-width theWorkingLayer)))
                (set! theLayerHeight (car(gimp-drawable-height theWorkingLayer)))
            );end begin
            )
        );end cond
        );end if

        ;work on the layer if it has not been already deleted

        (if (= theDeleted 0)

        ;if the layer is completely out of the bottom boundary delete it

        (cond ((> theOutDown (- theLayerHeight 1)) 
            (begin
                (gimp-image-remove-layer inImg theWorkingLayer)
                (set! theDeleted 1)
            );end begin
              )
              ((> theOutDown 0)
            (begin

                ;resize the layer to fit the bottom boundary of the image.

                (gimp-layer-resize theWorkingLayer
                           theLayerWidth
                           (- theLayerHeight theOutDown)
                           0
                           0)

                ;update the dimensions of the layer

                (set! theLayerWidth (car(gimp-drawable-width theWorkingLayer)))
                (set! theLayerHeight (car(gimp-drawable-height theWorkingLayer)))
            );end begin
            )
        );end cond
        );end if

        (set! theOutRight 0)
        (set! theOutDown 0)

        ;do not increase the counter if the layer has been deleted to consider the layer number variation
        ;caused by the removal. For the same reason reduce the number of layers by one.

        (if (= theDeleted 0)
        (set! theIterations (+ theIterations 1))
	(set! theLayerNum (- theLayerNum 1))
        )

        (set! theDeleted 0)

    );end while

    ;end undo group

    (gimp-image-undo-group-end inImg)

    (gimp-displays-flush)

    (list inImg inDrawable theLayerNum)

    );end let

);end define