Title: Using the Gimp - scripting/image conversion Post by: David Makin on January 15, 2012, 02:27:57 PM Hi all,
I recently installed the Gimp, have not used it much but noticed it has scripting - does anyone have sample scripts they could send me ? I want to do the following: Recursively: 1. load each png file from folder 1 (all files are >=3000pixels per side) 2. Resize (Lanczos) so the width is <=1280 and the height is <=960, keeping the aspect ratio 3. Save the result to folder 2 as a jpg at a fixed compression for all If that's not possible with the Gimp I'm open to any other *free* suggestions - otherwise I'll just have to write my own code to do it :) (In which case has anyone got the source for resizing using Lanczos ideally objectiveC but C or C++ would do ??) Title: Re: Using the Gimp - scripting/image conversion Post by: Sockratease on January 15, 2012, 03:20:47 PM I've been using pixresizer for many years.
http://pixresizer.en.softonic.com/ It handles folders in the way you want, but it's just a dedicated little program with no other functions. No image editing, scripting, or anything - but for batch resizing it's quick and easy. It only defines the longest side in pixels, so if some are taller than wide, it will only change the larger of the two dimensions. Hope it helps. Title: Re: Using the Gimp - scripting/image conversion Post by: taurus on January 15, 2012, 03:42:01 PM there are many readymade scripts on the net for standard quests lake scaling. searching google for "script fu scale" (script fu is the language) you find lots of them (e.g. http://registry.gimp.org/node/25350 (http://registry.gimp.org/node/25350)) they are easy to customize. searching "script fu lanczos" shows some snippets for the right interpolation and so on.
hope that helps ;D Title: Re: Using the Gimp - scripting/image conversion Post by: lycium on January 15, 2012, 05:06:39 PM I want to do the following: Recursively: 1. load each png file from folder 1 (all files are >=3000pixels per side) 2. Resize (Lanczos) so the width is <=1280 and the height is <=960, keeping the aspect ratio 3. Save the result to folder 2 as a jpg at a fixed compression for all that's a bad way to do it, because each step introduces roundoff error; all images should be made from the best possible source data. Title: Re: Using the Gimp - scripting/image conversion Post by: Syntopia on January 15, 2012, 06:14:47 PM If you are very serious about scaling, you should take gamma correction into acount (most software doesn't):
http://www.4p8.com/eric.brasseur/gamma.html (GIMP script examples at the bottom). Title: Re: Using the Gimp - scripting/image conversion Post by: David Makin on January 15, 2012, 08:21:35 PM Lighten up - they're just for the web !!
Anything less than 4000 pixels per side isn't worth that much hassle - bicubic would be fine, it would just be nice to use Lanczos... As for gamma, again bothering with that for web purposes is completely pointless for almost any image size because individual video cards and monitors vary more than the accuracy covered by doing gamma correction by eye (I mean on systems that supposedly have the same gamma correction) primarily due to the presence of *user adjustments* at both software and hardware levels - this will always be true unless a law is passed to force the general public to color correct their displays ;) Title: Re: Using the Gimp - scripting/image conversion Post by: David Makin on January 15, 2012, 08:30:02 PM I want to do the following: Recursively: 1. load each png file from folder 1 (all files are >=3000pixels per side) 2. Resize (Lanczos) so the width is <=1280 and the height is <=960, keeping the aspect ratio 3. Save the result to folder 2 as a jpg at a fixed compression for all that's a bad way to do it, because each step introduces roundoff error; all images should be made from the best possible source data. Exactly how does step 1 introduce round-off error ? - png is an exact copy format !! Step 2 - I assume you mean that the Gimp resize does not use high colour resolution e.g. conversion to RGB word or float ? - frankly not necessary for web quality. Step 3. ???? Saving a jpg is saving a jpg (I believe the evil bits of jpg conversion can be disabled in the Gimp though I'm not sure and anyway they're only for web view in this case) Title: Re: Using the Gimp - scripting/image conversion Post by: David Makin on January 15, 2012, 08:33:22 PM I've been using pixresizer for many years. http://pixresizer.en.softonic.com/ It handles folders in the way you want, but it's just a dedicated little program with no other functions. No image editing, scripting, or anything - but for batch resizing it's quick and easy. It only defines the longest side in pixels, so if some are taller than wide, it will only change the larger of the two dimensions. Hope it helps. Thanks ! Title: Re: Using the Gimp - scripting/image conversion Post by: David Makin on January 15, 2012, 08:33:46 PM there are many readymade scripts on the net for standard quests lake scaling. searching google for "script fu scale" (script fu is the language) you find lots of them (e.g. http://registry.gimp.org/node/25350 (http://registry.gimp.org/node/25350)) they are easy to customize. searching "script fu lanczos" shows some snippets for the right interpolation and so on. hope that helps ;D Thanks ! Title: Re: Using the Gimp - scripting/image conversion Post by: David Makin on January 15, 2012, 09:27:41 PM Just to add - I did start off doing it "by hand" but there are over 650 images and I can only stand tedium so long.....
Title: Re: Using the Gimp - scripting/image conversion Post by: Syntopia on January 15, 2012, 10:10:46 PM Lighten up - they're just for the web !! Yes, It seems excessive :-) I think his point is valid, though - he is not trying to match a specific gamma calibration of the final output device - he just argues that any averaging, or filtering should not be done directly on final RGB values. Instead the values should be gamma corrected (pixel^2.2), and then processed, and finally inversed gamma corrected (pixel^(1/2.2)). E.g., if you average two pixels with RGB=0,0,0 and RGB=255,255,255 the result should be 186,186,186. (If you want to get the average luminance). Whether you choose the exact same gamma as the final output device is not important. Title: Re: Using the Gimp - scripting/image conversion Post by: David Makin on January 15, 2012, 10:22:41 PM Lighten up - they're just for the web !! Yes, It seems excessive :-) I think his point is valid, though - he is not trying to match a specific gamma calibration of the final output device - he just argues that any averaging, or filtering should not be done directly on final RGB values. Instead the values should be gamma corrected (pixel^2.2), and then processed, and finally inversed gamma corrected (pixel^(1/2.2)). E.g., if you average two pixels with RGB=0,0,0 and RGB=255,255,255 the result should be 186,186,186. (If you want to get the average luminance). Whether you choose the exact same gamma as the final output device is not important. Silly me - I assumed that would be done automagically !! I mean I assume if you resize in Photoshop it does exactly that, I'm certain that Preview does - and I'm also certain that the in-built image resizing at DA *does not* which makes worrying about the gamma too much pretty pointless ;) Title: Re: Using the Gimp - scripting/image conversion Post by: taurus on January 15, 2012, 10:36:59 PM i'm a bit confused :hmh:. even i with my aversion against all kinds of command lines, would have tried to automate such a dull job.
if you're ready for some compromise (sort of gui clicking) on your way to nirvana, i can recommend irfranview. it has a really nice batch conversion with loads of options (including almost everything but the kitchen sink ;D) just by a few clicks and it is also available as portable app with no installation required. i convert all my digital photos for the web with it. Quote Yes, It seems excessive :-) this article seems some sort of academic to me. not many images fit the conditions of those very special examples. (while i didn't read the whole article - i'm not nuts :crazyeyes:) but downsizing very fine structures - just like fractals often provide - might really be tricky, and a thread of its own.Title: Re: Using the Gimp - scripting/image conversion Post by: huminado on January 15, 2012, 11:53:33 PM Just to add - I did start off doing it "by hand" but there are over 650 images and I can only stand tedium so long..... Holy cow. Keep a .txt file somewhere (I keep mine in my scripts directory) that gives the Gimp command line syntax: gimp -i -b '(batch-unsharp-mask "*.png" 5.0 0.5 0)' -b '(gimp-quit 0)' and your script file in the gimp directory (mine is C:\Program Files (x86)\GIMP-2.0\share\gimp\2.0\scripts) (define (batch-scale-then-oil pattern x y mask-size exponent ) (let* ((filelist (cadr (file-glob pattern 1)))) (while (not (null? filelist)) (let* ((filename (car filelist)) (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) (drawable (car (gimp-image-get-active-layer image)))) (gimp-levels-stretch drawable ) (gimp-image-scale image x y ) (plug-in-oilify RUN-NONINTERACTIVE image drawable mask-size 1 ) (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename) (gimp-image-delete image)) (set! filelist (cdr filelist))))) Of course my examples above aren't compatible with each other - but you get the idea. Even if there are other tools out there - sooner or later you'll want to use Gimp to batch process a movie to add some cool effect or adjust the colors or whatever. Title: Re: Using the Gimp - scripting/image conversion Post by: David Makin on January 16, 2012, 10:11:44 AM S'OK - I converted the first example last night to resize (as I wanted), conditionally sharpen and save using the full jpg option:
Code: ; A Script-Fu Script that Opens all files in a directory ; Creates and store away a copy of the files , the filename of the copy Title: Re: Using the Gimp - scripting/image conversion Post by: hobold on January 16, 2012, 02:50:06 PM To add more confusion: :) There is also "netpbm", a collection of classical unix command line tools for image processing. Shell scripts can then automate that. http://netpbm.sourceforge.net/ Netpbm uses a rather simplistic intermediate file format. This has downsides caused by a lack of features, but also upsides in that it is rather easy to program your own image filter if you want to tinker with exotic custom image processing. |