Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gimp Image slicing plugin for use with Motion 2. Note that this information is probably out of date. It is being added here for reference/archival purposes and relates to a blog post from 2005
; 2011-03-24 - Note, Giuseppe's current version of this script can be found
; here:
; and here:
; I think I only modified the two lines mentioned below, but it was a few years
; ago and I can't diff against the original code as Giuseppe has updated it
; since.
;;; image-subdivide.scm
;;; Arch. Giuseppe Conte <>
;;; Slightly modified by i5m ( 29-Dec-2005 to number images sequentially. See lines 102, 105 and 137
;;; 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
;;; 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 the function:
(define (script-fu-image-subdivide inImage inLayer nRighe nColonne option)
;; salva il nome del file origine
(set! orFilename (car (gimp-image-get-filename inImage)))
(set! orWidth (car (gimp-image-width inImage)))
(set! orHeight (car (gimp-image-height inImage)))
(set! newW (/ orWidth nColonne) )
(set! newH (/ orHeight nRighe) )
;;determina l'estensione del file origine
(set! name-length (length orFilename))
(set! inizio (- name-length 4))
(set! extension (substring orFilename inizio name-length))
; (gimp-message extension)
;;fine estensione file
;imposta l'estensione se il file deve essere salvato in un altro formato
( (= option 1) (set! extension ".png"))
( (= option 2) (set! extension ".jpg"))
( (= option 3) (set! extension ".bmp"))
( (= option 4) (set! extension ".tif"))
( (= option 5) (set! extension ".tga"))
;determina il tipo di immagine (RGB, GRAY, INDEXED)
(set! type (car (gimp-image-base-type inImage)))
;;imposto il ciclo per la suddivisione dell'immagine
(set! contaR 1)
(set! contaC 1)
(set! inXorig 0)
(set! inYorig 0)
(set! inWidth newW)
(set! inHeight newH)
(set! cnt 1)
(set! filename (car (gimp-image-get-filename inImage)))
(while ( <= contaR nRighe)
(set! inWidth newW)
(set! inHeight newH)
(while ( <= contaC nColonne)
;seleziona e copia una porzione dell'immagine
(gimp-rect-select inImage inXorig inYorig inWidth inHeight REPLACE FALSE 0)
(gimp-edit-copy inLayer)
;imposta la nuova immagine ed incolla la selezione
(set! newimage (car (gimp-image-new inWidth inHeight type)))
(set! newlayer (car (gimp-layer-new newimage inWidth inHeight type "Sfondo" 100 NORMAL)))
(gimp-image-add-layer newimage newlayer 0)
(gimp-drawable-fill newlayer BG-IMAGE-FILL)
(set! activelayer (car (gimp-image-set-active-layer newimage newlayer)))
(set! floating-sel (car (gimp-edit-paste newlayer FALSE)))
(gimp-floating-sel-anchor floating-sel)
;(gimp-display-new newimage)
;(script-fu-selection-to-image inImage inLayer )
;;imposta ed assegna un nome al nuovo file (nomefile-riga-colonna)
(set! filename (car (gimp-image-get-filename inImage)))
(set! count (number->string cnt)) ;i5m
(set! cnt (+ cnt 1))
(set! post "")
(set! post (string-append count)) ;i5m
; (set! filename (string-append (substring filename 0 (string-search "." filename)) post ".png" ""))
(set! filename (string-append (substring filename 0 (string-search "." filename)) post extension))
(gimp-image-set-filename newimage filename)
;(gimp-message filename)
(gimp-file-save 1 newimage newlayer filename filename)
; (file-png-save 1 newimage newlayer filename filename FALSE 6 FALSE TRUE TRUE TRUE TRUE)
;;fine prove
(set! inXorig (+ inXorig newW)) ;origine x rettanglo di selezione
(set! contaC (+ contaC 1))
);end while col
(set! contaC 1)
(set! inYorig (+ inYorig newH))
(set! inXorig 0)
(set! contaR (+ contaR 1))
);end while row
"<Image>/Script-Fu/i5m/Image subdivide";i5m
"Subdivide the image in MxN Rows and Columns and save any rectangular portion in the new files."
"Arch. Giuseppe Conte"
"2003, Conte Giuseppe"
"22 Agosto, 2003 - 72026 San Pancrazio Salentino (BR) - ITALY"
SF-IMAGE "The Image" 0
SF-DRAWABLE "The Layer" 0
SF-ADJUSTMENT "Rows " '(3 0 99999999 1 10 0 1)
SF-ADJUSTMENT "Columns" '(3 0 99999999 1 10 0 1)
SF-OPTION "Save as" '("Default" ".png" ".jpg" ".bmp" ".tif" ".tga")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment