;******************************************************************************* ;* Copyright (c) 2005 IBM Corporation and others. ;* All rights reserved. This program and the accompanying materials ;* are made available under the terms of the Common Public License v1.0 ;* which accompanies this distribution, and is available at ;* http://www.eclipse.org/legal/cpl-v10.html ;* ;* Contributors: ;* IBM Corporation - initial API and implementation ;*******************************************************************************/ ; Scale all images matching a given pattern by the provided scaling factor. An html ; file containing links to the original as well as image tags will be created. (define (batch-scale pattern factor htmlfile) (set! output (fopen htmlfile "w")) (let* ((filelist (cadr (file-glob pattern 1)))) (while filelist (let* ((filename (car filelist)) (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) (newfilename (string-append "T_" filename)) ) (pre-process image) (set! dimensions (scale-by-factor image factor)) (post-process image) (make-html output filename newfilename dimensions) (set! drawable (car (gimp-image-get-active-drawable image))) (gimp-file-save RUN-NONINTERACTIVE image drawable newfilename newfilename) (gimp-image-delete image) ) (set! filelist (cdr filelist)) ) (fclose output) )) ; Perform pre-scaling processing to the image. Currently a no-op. (define (pre-process image) ) ; Perform post-scaling processing to the image. Currently applies an unsharpen mask to ; the image. (define (post-process image) (gimp-image-undo-group-start image) (set! drawable (car (gimp-image-get-active-drawable image))) (plug-in-unsharp-mask 1 image drawable 1.0 0.3 0) (gimp-image-undo-group-end image) (gimp-displays-flush) ) ; Write an href/image pair to the html file. (define (make-html output link thumbnail dimensions) (fwrite "" output) (fwrite "string (car dimensions) 10) output) (fwrite "\" height=\"" output) (fwrite (number->string (cadr dimensions) 10) output) (fwrite "\">" output) ) ; Scale the image by the given factor. Returns the new width and height. (define (scale-by-factor image factor) (gimp-image-undo-group-start image) (gimp-image-flatten image) (set! width (* (car (gimp-image-width image)) factor)) (set! height (* (car (gimp-image-height image)) factor)) (gimp-image-scale image width height) (gimp-image-undo-group-end image) (gimp-displays-flush) (list width height) ) ; Registers the script with The Gimp. (script-fu-register "batch-scale" "/Xtns/Script-Fu/Scale By Factor" "Scale a batch of images by a certain factor and write an html file." "Kim Horne " "IBM Corporation" "12/02/2005" "" SF-VALUE "File pattern" "*.JPG" SF-VALUE "Scaling factor (float)" ".25" )