; images-to-brushes v2.1 ; Copyright (c) 2005 Adrian Likins ; adrian@gimp.org ; ; You specify a dir of images (say, an unzip "imagepack") and tell it ; what kind of file (.jpg, etc) what you want the default brush spacing to ; be, and it should be greyscale or not (yes, for most imagepacks I've seen, ; if the images actually have color and transparency, turn this off). ; ; The script then loads all the files in that dir that match the extention, ; and saves them as brushes. It tries to pick a sane filename and brushname ; based on the filename of the image. ; ; If the image has a lot of blankspace around it, you can select "autocrop" ; to try to crop out the blankspace before saving ; ; Also, the "Brushes->To Hose" will save all the images as an image hose. ; Though you need to specify the file name and the selection mechanism ; 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-selection-to-brush-local image drawable name filename spacing) (let* ((type (car (gimp-drawable-type-with-alpha drawable))) (selection-bounds (gimp-selection-bounds image)) (select-offset-x (cadr selection-bounds)) (select-offset-y (caddr selection-bounds)) (selection-width (- (cadr (cddr selection-bounds)) select-offset-x)) (selection-height (- (caddr (cddr selection-bounds)) select-offset-y))) (gimp-context-push) (gimp-image-undo-disable image) (if (= (car (gimp-selection-is-empty image)) TRUE) (begin (gimp-selection-layer-alpha drawable) (set! from-selection FALSE)) (begin (set! from-selection TRUE) (set! active-selection (car (gimp-selection-save image))))) (gimp-edit-copy drawable) (set! brush_draw_type (if (= type GRAYA-IMAGE) GRAY-IMAGE RGBA-IMAGE)) (set! brush_image_type (if (= type GRAYA-IMAGE) GRAY RGB)) (set! brush-image (car (gimp-image-new selection-width selection-height brush_image_type))) (set! brush-draw (car (gimp-layer-new brush-image selection-width selection-height brush_draw_type "Brush" 100 NORMAL-MODE))) (gimp-image-add-layer brush-image brush-draw 0) (gimp-selection-none brush-image) (if (= type GRAYA-IMAGE) (begin (gimp-context-set-background '(255 255 255)) (gimp-drawable-fill brush-draw BACKGROUND-FILL)) (gimp-drawable-fill brush-draw TRANSPARENT-FILL)) (let ((floating-sel (car (gimp-edit-paste brush-draw FALSE)))) (gimp-floating-sel-anchor floating-sel)) (set! filename2 (string-append gimp-directory "/brushes/" filename (number->string image) ".gbr")) (file-gbr-save 1 brush-image brush-draw filename2 "" spacing name) (if (= from-selection TRUE) (begin (gimp-selection-load active-selection) (gimp-image-remove-channel image active-selection))) (gimp-image-undo-enable image) (gimp-image-set-active-layer image drawable) (gimp-image-delete brush-image) (gimp-context-pop) ; we dont really want to change the active brush for this ;(gimp-context-set-brush name) )) ; lame-tastic (define (get-selection-mode index) (set! sellist (list "incremental" "random" "angular" "velocity" "pressure" "xtilt" "ytilt")) (list (nth index sellist ))) (define (script-fu-images-to-image-hose directory fileex brushname convert autocrop selection spacing) (let* ((files (file-glob (string-append directory "/*" fileex) 0)) (dirlength (string-length directory)) (numfiles (car files)) (maxheight 0) (maxwidth 0) (image-list '()) (filelist (cadr files))) (if (= (length filelist) 0) (gimp-message "No files were found. Check the folder path, and the file extention")) (while filelist (set! imagename (car filelist)) (set! image (car (gimp-file-load 1 imagename imagename))) (set! filelist (cdr filelist)) (set! drawable (car (gimp-image-get-active-drawable image))) (set! height (car (gimp-image-height image))) (set! width (car (gimp-image-width image))) ; calculate the biggest image (if (> width maxwidth) (set! maxwidth width)) (if (> height maxheight) (set! maxheight height)) ; handle gifs, convert to rgb (if (= (gimp-drawable-is-indexed drawable) TRUE) (begin (gimp-image-convert-rgb image))) ; most brush packs are jpg/pngs that are rgb, but are only greyscale, ; so by default, we convert to grayscale. Leave this off if you want ; to save pixmap images (if (= convert TRUE) (begin (gimp-image-convert-grayscale image))) ; most images packs seem to have cropped properly before hand, but ; give users the option if thats not the case (if (= autocrop TRUE) (begin (plug-in-autocrop 1 image (car (gimp-image-get-active-drawable image))))) ; append the new image to the list (set! image-list (append image-list (list image))) ) ; create a new image of maxheight/width, so we can paste the other images in ; as layers to save as an image hose (set! brush-image (car (gimp-image-new maxwidth maxheight 0))) (while image-list (set! layer-image (car image-list)) (set! image-list (cdr image-list)) (set! brush-drawable (car (gimp-layer-new brush-image (car (gimp-image-width layer-image)) (car (gimp-image-height layer-image)) 0 "layer" 100.0 0))) ; add the new image, just stick it at the bottom (gimp-image-add-layer brush-image brush-drawable 0) ; layers are full of bogus crap if you dont clear them (gimp-edit-clear brush-drawable) ; select the src image (gimp-selection-all layer-image) ; copy the whole image (gimp-edit-copy (car (gimp-image-get-active-drawable layer-image))) ; paste into the new layer, get a floating selection back (set! floating (car (gimp-edit-paste brush-drawable 0))) ; anchor the floating selection (gimp-floating-sel-anchor floating) ; clean up all the temp images (gimp-image-delete layer-image) ) ; oh my, does string handling suck in script-fu. This is all weirdness to try ; to get a good filename and brush name (set! rawfilename (substring imagename dirlength (string-length imagename))) (set! filename (substring rawfilename 1 (- (string-length rawfilename) (string-length fileex)))) (set! filename (string-append gimp-directory "/brushes/" brushname ".gbr")) (set! rank (cons-array 1 'byte)) (aset rank 0 1) (file-gih-save 1 brush-image brush-drawable filename filename spacing filename maxwidth maxheight 1 1 1 rank 1 (list (get-selection-mode selection))) ; (file-gih-save 1 brush-image brush-drawable filename filename spacing filename maxwidth maxheight 1 1 1 rank 1 (list "random")) ; let folks see there shiny new brush (gimp-brushes-refresh) ; cleanup, we dont really need this image any nore (gimp-image-delete brush-image) )) (define (script-fu-images-to-brushes directory fileex convert autocrop spacing) (let* ((files (file-glob (string-append directory "/*" fileex) 0)) (dirlength (string-length directory)) (numfiles (car files)) (filelist (cadr files))) (if (= (length filelist) 0) (gimp-message "No files were found. Check the folder path, and the file extention")) (while filelist (set! imagename (car filelist)) (set! image (car (gimp-file-load 1 imagename imagename))) (set! filelist (cdr filelist)) (set! drawable (car (gimp-image-get-active-drawable image))) ; handle gifs, convert to rgb (if (= (gimp-drawable-is-indexed drawable) TRUE) (begin (gimp-image-convert-rgb image))) ; most brush packs are jpg/pngs that are rgb, but are only greyscale, ; so by default, we convert to grayscale. Leave this off if you want ; to save pixmap images (if (= convert TRUE) (begin (gimp-image-convert-grayscale image))) ; most images packs seem to have cropped properly before hand, but ; give users the option if thats not the case (if (= autocrop TRUE) (begin (plug-in-autocrop 1 image (car (gimp-image-get-active-drawable image))))) (gimp-selection-all image) ; oh my, does string handling suck in script-fu. This is all weirdness to try ; to get a good filename and brush name (set! rawfilename (substring imagename dirlength (string-length imagename))) (set! filename (substring rawfilename 1 (- (string-length rawfilename) (string-length fileex)))) ; reuse the code from selection-to-brush, slightly tweaked so we dont refresh all the time (script-fu-selection-to-brush-local image drawable filename filename spacing) (gimp-image-delete image) ) ; refresh the brush palette now that we've added all the brushes (gimp-brushes-refresh) ) ) (script-fu-register "script-fu-images-to-brushes" _"Images To _Brush..." "Convert a directory of images (aka, an unzipped imagepack) to a set of brushes" "Adrian Likins " "Adrian Likins" "12/15/2005" "" SF-DIRNAME _"Directory of images" "/path/to/dir/of/images" SF-STRING _"file extention" ".jpg" SF-TOGGLE _"convert to grayscale?" TRUE SF-TOGGLE _"autocrop?" FALSE SF-ADJUSTMENT _"Spacing" '(25 0 1000 1 1 1 0)) (script-fu-menu-register "script-fu-images-to-brushes" "/Xtns/Brushes") (script-fu-register "script-fu-images-to-image-hose" _"Images To _Hose...(beta)" "Convert a directory of images (aka, an unzipped imagepack) to an image hose brush" "Adrian Likins " "Adrian Likins" "12/16/2005" "" SF-DIRNAME _"Directory of images" "/path/to/where/your/files/are" SF-STRING _"File extention" ".jpg" SF-STRING _"Brush name" "untitled" SF-TOGGLE _"convert to grayscale?" TRUE SF-TOGGLE _"autocrop?" FALSE SF-OPTION _"selectionmode" '("incremental" "random" "angular" "velocity" "pressure" "xtilt" "ytilt") SF-ADJUSTMENT _"Spacing" '(25 0 1000 1 1 1 0)) (script-fu-menu-register "script-fu-images-to-image-hose" "/Xtns/Brushes")