Quantcast
Channel: Adobe Community: Message List - Photoshop Scripting
Viewing all articles
Browse latest Browse all 27456

Re: Cropping multiple Images from single file

$
0
0

Thanks Michael this was a life saver XD I changed it for PNG and figured out the folder system for a Mac which is basically the same for windows just changed the starting dir. Oh and I'm using this in Adobe Photoshop CS5. If you don't want to read above ^ Copy the code into applications>utilities>adobe utilities - C5>ExtendScript Toolkit.app

 

Then save it somewhere where you can find it. Then in photoshop with your image open go file>scripts>browse and find where you saved the script and select it.

 

***Hmmm is only letting me save up to 8 in one folder then cut them over and start again.

 

// This script will save the active document to a folder with an incremental sufix

// Change the options below to match your needs

var saveFolder = new Folder( '/Users/name/foldername' ); //don't put the ending "/" this is for mac folders windows is /c/foldername

var saveSufixStart = '_';

var saveSufixLength = 3;

saveOptions = new PNGSaveOptions();

saveOptions.embedColorProfile = true;

saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

saveOptions.matte = MatteType.NONE;

saveOptions.quality = 8;

// End of user options

//==========================================

var saveExt = 'png';

function zeroPad ( num, digit ){

   var tmp = num.toString();

   while (tmp.length < digit) { tmp = "0" + tmp;}

   return tmp;

}

var docName = decodeURI ( activeDocument.name );

docName = docName.match( /(.*)(\.[^\.]+)/ ) ? docName = docName.match( /(.*)(\.[^\.]+)/ ) : docName = [ docName, docName, undefined ];

var saveName = docName[ 1 ]; // activeDocument name with out ext

var files = saveFolder.getFiles( saveName + '*.' + saveExt );// get an array of files matching doc name prefix

 

 

if( files.length == 0 ) {  // no file with that name so start at one

   var saveNumber = 1;

}

if( files.length == 1 ) { // one file found, see if it has a sufix

   var fileName = decodeURI ( files[ 0 ].name );

   fileName = fileName.match( /(.*)(\.[^\.]+)/ ) ? fileName = fileName.match( /(.*)(\.[^\.]+)/ ) : fileName = [ fileName, fileName, undefined ];

   if( fileName[1].match( /_(\d{3})$/ ) == null ){

      var saveNumber = 1;// does not have sufix so set to one

   } else{// has sufix

      var saveNumber = parseInt( fileName[ 1 ].match( /_(\d{3})$/ )[1] ) + 1; // strip the ext and get the sufix , convert to number and add 1

   }

}

if( files.length > 1 ){

   files.sort();

   var fileName = decodeURI ( files[ files.length -1 ].name );

   fileName = fileName.match( /(.*)(\.[^\.]+)/ ) ? fileName = fileName.match( /(.*)(\.[^\.]+)/ ) : fileName = [ fileName, fileName, undefined ];

   var saveNumber = parseInt( fileName[ 1 ].match( /_(\d{3})$/ )[1] ) + 1; // strip the ext and get the sufix , convert to number and add 1

}

var saveFile = new File( saveFolder + '/' + saveName + '_' + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );

activeDocument.saveAs( saveFile, saveOptions ,true ,Extension.LOWERCASE);

Thanks again Michael XD


Viewing all articles
Browse latest Browse all 27456

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>