; The GIMP -- an image manipulation program ; Copyright (C) 1995 Spencer Kimball and Peter Mattis ; ; image to layersize ; Copyright (c) 2002 Simon Budig ; simon@gimp.org ; ; 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. (define (script-fu-image-to-layersize image drawable) (let* ((min-x 0) (max-x 0) (min-y 0) (max-y 0) (cur-min-x 0) (cur-max-x 0) (cur-min-y 0) (cur-max-y 0) (offsets '(0 0)) (layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (i 0)) (if (> num-layers 0) (begin (set! offsets (gimp-drawable-offsets (aref layer-array i))) (set! min-x (car offsets)) (set! min-y (cadr offsets)) (set! max-x (+ (car offsets) (car (gimp-drawable-width (aref layer-array i))))) (set! max-y (+ (cadr offsets) (car (gimp-drawable-height (aref layer-array i))))) (set! i 1) (while (< i num-layers) (set! offsets (gimp-drawable-offsets (aref layer-array i))) (set! cur-min-x (car offsets)) (set! cur-min-y (cadr offsets)) (set! cur-max-x (+ (car offsets) (car (gimp-drawable-width (aref layer-array i))))) (set! cur-max-y (+ (cadr offsets) (car (gimp-drawable-height (aref layer-array i))))) (if (< cur-min-x min-x) (set! min-x cur-min-x)) (if (> cur-max-x max-x) (set! max-x cur-max-x)) (if (< cur-min-y min-y) (set! min-y cur-min-y)) (if (> cur-max-y max-y) (set! max-y cur-max-y)) (set! i (+ i 1))) (gimp-image-resize image (- max-x min-x) (- max-y min-y) (- min-x) (- min-y)) (gimp-displays-flush))))) (script-fu-register "script-fu-image-to-layersize" _"/Image/Fit canvas to layers" "changes the canvas size of the image to contain all layers" "Simon Budig " "Simon Budig" "2002/9/2" "*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0)