summaryrefslogtreecommitdiffstats
path: root/kjsembed/docs/examples/imageinfo/imagescale.js
blob: d0921cd985a8c9b25fc966bd37ed0cae9bbd2955 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/opt/trinity/bin/kjscmd

//
// Load an image, scale it, and save it in the specified format.
//

if ( application.args.length >= 3 ) {
    var infile = application.args[0];
    var outfile = application.args[1];
    var scale = application.args[2];

    var img = new Image();
    img.load( infile );
    if ( img.isOk() ) {
	if ( application.args.length > 3 ) {
	    img.format = application.args[3];
	}

	img.smoothScale( img.width*(scale/100.0), img.height*(scale/100.0) );
	img.save( outfile );
    }
}
else {
    System.out.println( 'Usage:' );
    System.err.println( '\timagescale imgfile outfile percent [format]' );
}