Logo by LAR2 - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Follow us on Twitter
 
*
Welcome, Guest. Please login or register. March 28, 2024, 07:58:54 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1] 2   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Using the Gimp - scripting/image conversion  (Read 8408 times)
0 Members and 6 Guests are viewing this topic.
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« 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 smiley (In which case has anyone got the source for resizing using Lanczos ideally objectiveC but C or C++ would do ??)
Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
Sockratease
Global Moderator
Fractal Senior
******
Posts: 3181



« Reply #1 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.
Logged

Life is complex - It has real and imaginary components.

The All New Fractal Forums is now in Public Beta Testing! Visit FractalForums.org and check it out!
taurus
Fractal Supremo
*****
Posts: 1175



profile.php?id=1339106810 @taurus_arts_66
WWW
« Reply #2 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) they are easy to customize. searching "script fu lanczos" shows some snippets for the right interpolation and so on.

hope that helps  grin
Logged

when life offers you a lemon, get yourself some salt and tequila!
lycium
Fractal Supremo
*****
Posts: 1158



WWW
« Reply #3 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.
Logged

Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #4 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).
Logged
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #5 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 wink
« Last Edit: January 15, 2012, 08:32:17 PM by David Makin » Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #6 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. huh?? 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)
« Last Edit: January 15, 2012, 08:32:58 PM by David Makin » Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #7 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 !
Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #8 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) they are easy to customize. searching "script fu lanczos" shows some snippets for the right interpolation and so on.

hope that helps  grin

Thanks !
Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #9 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.....
Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #10 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.
Logged
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #11 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 wink

« Last Edit: January 15, 2012, 10:26:16 PM by David Makin » Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
taurus
Fractal Supremo
*****
Posts: 1175



profile.php?id=1339106810 @taurus_arts_66
WWW
« Reply #12 on: January 15, 2012, 10:36:59 PM »

i'm a bit confused  huh?. 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  grin) 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  crazy eyes) but downsizing very fine structures - just like fractals often provide - might really be tricky, and a thread of its own.
Logged

when life offers you a lemon, get yourself some salt and tequila!
huminado
Guest
« Reply #13 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.
Logged
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #14 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
; has a users defined suffix
; "Scaled" , "PNG to JPG"
; Written in Jan 2012

(define (script-fu-batch-scs globexp suffix bsharpen qual smooth opt progress sub base dct)

(let* ((filelist (cadr (file-glob globexp 1))))

(while (not (null? filelist))
     (let* ((fname (car filelist))
       
     (img (car (gimp-file-load RUN-NONINTERACTIVE fname fname))))
     (let* (
           (xdrawable   (car (gimp-image-active-drawable img)))
           (cur-width  (car (gimp-image-width img)))
           (cur-height (car (gimp-image-height img)))
           (new_ratio      (min (/ 1280 cur-width) (/ 960 cur-height)))
           (width      (* new_ratio cur-width))
           (height     (* new_ratio cur-height))
       )                 
       (gimp-image-undo-disable img)
       (gimp-image-scale-full img width height INTERPOLATION-LANCZOS)
; Sharpen if the user wants so
       (if (= bsharpen TRUE) (plug-in-sharpen RUN-NONINTERACTIVE img xdrawable 40))

  ;(gimp-message "Nu skall vi bara spara!")

(file-jpeg-save RUN-NONINTERACTIVE img xdrawable (string-append (car (strbreakup fname ".")) suffix) (string-append (car (strbreakup fname ".")) suffix) (/ qual 100.0) (/ smooth 100.0) opt progress "Hello" sub base 1 dct)

       ;(gimp-message "Nu har vi sparat!")
   
       ;(gimp-display-delete img) Lite synd att vi inte kan kˆra denna ... MÂste testa p bibliotek med mycket filer s det inte blir overflow
     )
    (set! filelist (cdr filelist)))))
)


; Register in Gimp Menu
(script-fu-register "script-fu-batch-scs"
    _"_Batch Scale/Sharpen.."
    "Scale and Sharpen many Pictures, Save them in new files"
    "Sven Tryding/David Makin"
    "2011, Sven Tryding, 2012 David Makin"
    "June, 2011/Jan 2012"
    ""
    SF-STRING "Path" "/Users/davemakin/Pictures/Photos/Processed/*14-1-2012.png"
              SF-STRING "Suffix" "_web.jpg"

              SF-TOGGLE "Sharpen (40%)" FALSE
              SF-VALUE "Quality (min 0.0, max 100.0)" "90.0"
              SF-VALUE "Smoothing (min 0.0, max 100.0)" "0.0"
              SF-TOGGLE "Optimise" TRUE
              SF-TOGGLE "Progressive" FALSE
              SF-VALUE "Sub-sample (min 0, max 2)" "2"
              SF-TOGGLE "Base-level JPG" FALSE
              SF-VALUE "DCT (min 0, max 2)" "2")

(script-fu-menu-register "script-fu-batch-scs"
"<Toolbox>/_Filters/_Script-Fu")

Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
Pages: [1] 2   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Apo7x scripting - Flame.height ? Help & Support barsichou 2 330 Last post May 16, 2013, 06:26:42 PM
by cKleinhuis
GIMP caching huge images to hard drive... Format, Printing & Post Production stardust4ever 0 2205 Last post September 17, 2014, 02:21:27 AM
by stardust4ever
can't filnd the scripting button. Apophysis Programs TsarveK 2 3049 Last post December 12, 2014, 09:18:57 PM
by lenord
Noob Question - Apophysis 7X, Can't find scripting window Help & Support ender 1 425 Last post January 28, 2016, 01:28:41 PM
by lycium
file conversion or other options? Fractal Programs Sortna 1 3800 Last post October 17, 2017, 03:00:58 PM
by Spain2points

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.146 seconds with 24 queries. (Pretty URLs adds 0.008s, 2q)