Archive

Archive for the ‘IT’ Category

Script-Fu Template For Batch Processing In GIMP

January 31, 2009 edwinhere 4 comments

Time and again, I’ve wanted to do a set of operations on a large set of images. I knew that Script-Fu in GIMP could do the job, but I could never find a boiler plate code to act on all files in a directory.

This is a little something I wrote to reduce the number of colors and remove the alpha channel of a large number of PNG files in a directory:

(define (smallify dir)
  (let*
    ((files-list (car (cdr (file-glob dir 0))))
     (do-one (lambda (f) (let*
                           ((i (gimp-file-load RUN-NONINTERACTIVE f f))
                            (d (gimp-image-flatten (car i))))
                           (begin
                             (gimp-posterize (car d) 5)
                             (file-png-save2 RUN-NONINTERACTIVE (car i) (car d)
                              f f 0 9 0 0 0 0 0 0 0)
                             #t)))))
    (map do-one files-list)))

Here is the generic template that can be used for batch processing a lot of images in one directory:

(define (do-many dir)
  (let*
    ((files-list (car (cdr (file-glob dir 0))))
     (do-one (lambda (f) (your-code-goes-here))))
    (map do-one files-list)))

In order to use the above template, first replace (your-code-goes-here) with the s-expression you need to change the images. (Hint: Use Filters > Script-Fu > Console > Browse… to see the documentation). While doing so keep in mind that f will contain the full path to each file in your directory; you can use f to do what you wish that file.

Then in Script-Fu console, paste the resulting code in the text field there and press enter. This will define the do-many function. Then you can call it like this:

(do-many "/home/edwin/alotafimages/*.png")

And your s-expressions will act on all PNG files in that directory.

Categories: IT, computers & foss, hacking

The Boy Who Cried Wolf

May 12, 2008 edwinhere Leave a comment

I think it was a bad strategy to evangelize for Linux before Hardy Heron. Because some of the users got fed up when they realized that they have to research for 72 hours on forums and IRCs to do simple tasks. As a result some quit the idea of using Linux altogether. So when we tell them Linux is now better than Windows, they think we are exaggerating.

But the boy is not dead; he is here to stay. Perhaps people will listen when he keeps crying for another 10 years.

Categories: IT