Objectif Lune joins Upland Software.Learn more >

Back to all How-tos

Resizing an image without an external application

This script uses a simplified function that demonstrates the use of the WIA object in Windows Scripting Host. It lets you resize images without the use of an external program or software, in a Workflow process.

There are a few examples of how to use the “Filters” to do different things, however note that the examples in the link below are for JavaScript and need to be adjusted in syntax to be used in this file: How to use Filters

Note that this script, normally used in a Workflow Run Script task, will get the image from the job data file and will directly save the output in the c:/out folder. Keep in mind that it’s possible to use the resize() function in any way you require.

// Set the path of the source image. This should be a full path either on a
// local drive, or a UNC path for a network file.

// This example loads the current job file.
var source_file = Watch.GetJobFilename();

// You could also use a full path:
// var source_file = 'C:/path/to/image.jpg';

// This sets the output path. This can be the same as the input and if so,
// it will overwrite the original file.
//var output_file = Watch.GetJobFilename();


// The following is the generic function that allows for image resize. 
// It uses the WIA object, see intro for link on more things you can do with it!
function resize(filename, newFile, maxwidth, maxheight) {
    var Img = new ActiveXObject("WIA.ImageFile");
    var IP = new ActiveXObject("WIA.ImageProcess");

    Img.LoadFile(filename);

    IP.Filters.Add(IP.FilterInfos("Scale").FilterID);
    IP.Filters(1).Properties("MaximumWidth") = maxwidth;
    IP.Filters(1).Properties("MaximumHeight") = maxheight;

    Img = IP.Apply(Img);
    Img.SaveFile(newFile);
}

resize(source_file, "c:/out/smallimage.jpg", "100", "150");

Leave a Reply

Your email address will not be published. Required fields are marked *