You are here

Another bulk processing question....

I'm wondering if its possible to write a script that will walk through a directory and convert all .xcf files into a .jpg file with a scale factor so that the new files will be appropriate for a web page. The current files are about 30MB in size and need to be converted to a jpg of < 2MB in size.


to gimp or not to gimp :-D GIIIMMMPPPP

Well, I figured it out for myself by plagiarizing someone else's script. It was a 2 step process. A script was written which takes one file as input in xcf format, 2 values for the x/y scaling factor and a jpeg output file. Here's the script tool: (define (native-to-jpg width height infile outfile) (let* ( (hd (car (gimp-message-set-handler 1))) (img (car (gimp-file-load 1 infile infile))) (drawable (car (gimp-image-active-drawable img)))) (gimp-image-scale img width height) (file-jpeg-save 1 img drawable outfile outfile 0.8 0 1 1 "No comment!" 0 1 0 0) ) ) (script-fu-register "native-to-jpg" "/Xtns/Script-Fu/Tools/Native-to-Jpg" "Native-to-Jpg" "" "my name" "2008-03-24" "" SF-VALUE "Width" "100" SF-VALUE "Height" "100" SF-FILENAME "Infile" "infile.xcf" SF-FILENAME "Outfile" "outfile.jpg" ) Once I had this I could process a single file at a time within gimp. Next I wrote a shell script that walked through a directory, found all of the files I wanted, passed them through gimp using the script I had written along with some parameters for the x/y scale factors and the output file name (along with a directory name). Here's the shell script: #!/bin/sh outDir=jpgDir inDir=./ xAspect=1000 yAspect=1000 while [ "$1" != "" ] # When there are arguments... do case $1 in -i) inDir=$2; # If it's a "-i", set input directory name shift 2;; # Shift two argument along -o) outDir=$2; # If it's a "-o", set output directory name shift 2;; # Shift two argument along -r) xAspect=$2; # If it's a "-r", set X aspect and Y aspect yAspect="$3"; shift 3;; # Shift three argument along *) echo "Option [$1] not one of [i ,o, r]"; # Error (!) exit;; # Abort Script Now esac done mkdir -p $outDir for file in *.xcf; do echo Working on file: $file newFile="$(echo "$file" | sed 's/xcf/jpg/')" echo output File: $newFile gimp --display :1.0 -c -d -b\ '(native-to-jpg '$xAspect' '$yAspect' "'$file'" "'$outDir'/'$newFile'")'\ -b '(gimp-quit 0)' done You need to make sure you have a frame buffer server running on the same display output designated in the call to "gimp". In this case :1.0. You can do this by running this command before starting the scripts: Xvfb :1 -screen 0 10x10x8 this will run the frame buffer on screen 0 in a very minimal memory configuration. Anyways, I'm hoping to get people to comment on my method for doing this. It works but I can't say if this is the best way. Cheers!!
Subscribe to Comments for "Another bulk processing question...."