PhotoshopForums.com Home
Navigate Contact FAQ Search Members
Batch resize variety of differet sized images
Post new topic   Reply to topic    PhotoshopForums.com Forum Index -> Actions and Automation
 See a User Guidelines violation? Please contact us.
Author Message

kyllle

Joined: 30 Jun 2008
Posts: 7



PostPosted: Tue Sep 28, 2010 9:43 am    Post subject: Batch resize variety of differet sized images Reply with quote

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
View user's profile Send private message

Paul R

Joined: 06 Apr 2010
Posts: 57



PostPosted: Tue Sep 28, 2010 11:35 am    Post subject: Reply with quote

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);
}
View user's profile Send private message

Damo77

Joined: 28 Aug 2010
Posts: 114
Location: Brisbane, Australia


PostPosted: Tue Sep 28, 2010 3:23 pm    Post subject: Reply with quote

Are you saying you want all your images to be square, regardless of their original shape? Or are you saying you want them to keep their original shape, but not exceed either 250 wide or high?
_________________
http://www.damiensymonds.com.au/
http://damiensymonds.blogspot.com/
View user's profile Send private message Visit poster's website

hawkeye

Joined: 14 May 2009
Posts: 2377
Location: Mesa, Az

OS: Windows 7 Pro 64 bit

PostPosted: Wed Sep 29, 2010 10:00 am    Post subject: Reply with quote

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.
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PhotoshopForums.com Forum Index -> Actions and Automation All times are GMT - 6 Hours
Page 1 of 1
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Contact - User Guidelines >

Copyright © 2003-2016. PhotoshopForums.com, iFroggy Network. All Rights Reserved.
Powered by phpBB © phpBB Group. phpBB SEO. Privacy Policy.
We are in no way affiliated with Adobe. Photoshop, Adobe and related marks are registered trademarks of Adobe.
PhotoshopForums.com