Blog
New i.Mage Scripting Functionality
Date: 17/9/2008
Every now and then I need to generate a directory of thumbnails from a set of photos. This is painful doing it by hand so in a moment of inspiration I thought that i.Mage could be scripted to do just that. (der!)

So with the addition of a few simple functions I came up with this little jem of a script:
f = SelectFiles(Parent, "Jpeg *.jpg", 0, 1);
if (f)
{
    for (i=0; i<f.Length; i++)
    {
        File = f[i];    
        Load(File);
        
        Doc = GetDocument();
        Print("Doc = " + Doc.x + "x" + Doc.y + " @ " + Doc.Bits + "\n");
        
        Aspect = 1.0 * Doc.x / Doc.y;
        Nx = 320;
        Ny = Nx / Aspect;
        Print("Aspect = " + Aspect + " " + Nx + "x" + Ny + "\n");
        
        Resample(Nx, Ny);
        
        Dot = Strchr(File, ".", -1, 1);
        Base = Substr(File, 0, Dot);
        Ext = Substr(File, Dot+1);
        Small = Base + "_s." + Ext;
        Print("Small=" + Small + "\n");
        
        Save(Small, "quality=40");
    }
}
It opens a file selection dialog at the top and then proceeds to convert each file down to 320 px across and saves it out to "filename_s.ext".

Then I got to thinking, that this could ship with the product and hang off a tools menu so that other people can use it too. Or at least it there needs to be a directory of scripts that you can access in the editor rather than just what you were working on last.

Hmmmm.

There is a new function GetDocument() that returns the current document (in the form of a GVariant containing a GSurface) which has a few properties like "x", "y" and "Bits". There is some new scripting abilities in the pipes to allow the engine to call methods on Dom objects. This could pave the way to code like:

GetDocument().Create(640, 480, 32);


Which would be quite nice. I've also started putting some of the standard image wide transforms into functions so that you can call them from scripts. i.e. the Resample() method.
Comments:
Josh
17/09/2008 6:55am
Very nifty. I like the looks of this for some stuff I've been doing lately. Folder full of 10MP pics, straight from the camera, wife wants to upload to Facebook album. Convert pics so it doesn't take as long to upload them. Batch convert would be best, but not easily scriptable, except, now it seems to be.

Now, the only question I have is: Will this preserve IPTC and XMP headers on pictures that have been tagged using iTag - http://www.itagsoftware.com ? Also, can you look at the EXIF data to see if this should be portrait style rather than landscape?

Thanks,

Josh
 
Reply
From:
Email (optional): (Will be HTML encoded to evade harvesting)
Message:
 
Remember username and/or email in a cookie.
Notify me of new posts in this thread via email.
BBcode:
[q]text[/q]
[url=link]description[/url]
[img]url_to_image[/img]
[pre]some_code[/pre]
[b]bold_text[/b]