|
Author |
Message |
kyllle
Joined: 30 Jun 2008
Posts: 7
|
Posted: Tue Sep 28, 2010 9:43 am Post subject: Batch resize variety of differet sized images |
|
|
Hi all,
Im trying to find out a way in which I can batch resize a folder of images that are currently varied in size. I want to be able to run a script which will resize all the images strictly to the size of 250px x 250px without compromising the quality so no stretching etc. The current sizes vary from 870px x 400px to 1020px x 520px
I know I can batch resize using photoshop or various applications but I find that in order to fill the 250x250 size sometimes the image has to be stretched if it is quite thin to begin with
All advice would be appreciated loads.
Thanks |
|
|
|
|
Paul R
Joined: 06 Apr 2010
Posts: 57
|
Posted: Tue Sep 28, 2010 11:35 am Post subject: |
|
|
The only true way to do this is to resize the picture to 250 pixels on the longest side then alter the canvas size to 250 x 250pixels.
The following code should do this...
Code: |
#target photoshop
main();
function main(){
var inputFolder = Folder.selectDialog("Please select the folder with Files to process");
if( inputFolder == null ) return;
var outputFolder = Folder.selectDialog("Please select the output folder");
if( outputFolder == null ) return;
var fileList = inputFolder.getFiles(/\.(jpg|tif|psd|png)$/i);
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
var White = new SolidColor;
White.rgb.hexValue = 'ffffff';
backgroundColor = White;
for(var a in fileList){
open(fileList[a]);
app.activeDocument.flatten();
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
FitImage( 250, 250);
app.activeDocument.resizeCanvas(250, 250, AnchorPosition.MIDDLECENTER);
var saveFile = File(outputFolder + "/" + Name + ".jpg");
SaveForWeb(saveFile,80);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
}
function FitImage( inWidth, inHeight ) {
if ( inWidth == undefined || inHeight == undefined ) {
alert( "FitImage requires both Width & Height!");
return 100;
}
var desc = new ActionDescriptor();
var unitPixels = charIDToTypeID( '#Pxl' );
desc.putUnitDouble( charIDToTypeID( 'Wdth' ), unitPixels, inWidth );
desc.putUnitDouble( charIDToTypeID( 'Hght' ), unitPixels, inHeight );
var runtimeEventID = stringIDToTypeID( "3caa3434-cb67-11d1-bc43-0060b0a13dc4" );
executeAction( runtimeEventID, desc, DialogModes.NO );
}
function SaveForWeb(saveFile,jpegQuality) {
var sfwOptions = new ExportOptionsSaveForWeb();
sfwOptions.format = SaveDocumentType.JPEG;
sfwOptions.includeProfile = false;
sfwOptions.interlaced = 0;
sfwOptions.optimized = true;
sfwOptions.quality = jpegQuality; //0-100
activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);
}
|
|
|
|
|
|
Damo77
Joined: 28 Aug 2010
Posts: 114
Location: Brisbane, Australia
|
Posted: Tue Sep 28, 2010 3:23 pm Post subject: |
|
|
|
|
|
|
|
hawkeye
Joined: 14 May 2009
Posts: 2377
Location: Mesa, Az
OS: Windows 7 Pro 64 bit
|
Posted: Wed Sep 29, 2010 10:00 am Post subject: |
|
|
If you want rectangular originals to be resized square then you will have distortion. Or you will need to crop them and lose some of the image.
If you just want to resize all images to one maximum set size, record an action and use Fit Image. |
|
|
|
|
|