批量调整大小并输出多个图像

时间:2013-03-07 11:02:37

标签: image batch-file resize photoshop photoshop-script

我需要批量重新调整多个图像的尺寸,这在Photoshop插入文件夹并在另一个文件夹中获取输出时非常简单。

但我需要单张图片的多张图片。

我所拥有的是所有原始图像的文件夹以及我需要的每个图像的四个不同尺寸的文件夹,请参阅:

1 个答案:

答案 0 :(得分:0)

此脚本将执行您想要的操作:在名为“export”的目录中以gifs格式保存四个图像

app.preferences.rulerUnits = Units.PIXELS;

// call the source document
var srcDoc = app.activeDocument;
var imageWidth = srcDoc.width.value;
var imageHeight = srcDoc.height.value;
var resizeRes = 72;
fileName = app.activeDocument.name;
docName = fileName.substring(0,fileName.length -4);

//turn it RGB
var id60 = charIDToTypeID( "CnvM" );
var desc12 = new ActionDescriptor();
var id61 = charIDToTypeID( "T   " );
var id62 = charIDToTypeID( "RGBM" );
desc12.putClass( id61, id62 );
executeAction( id60, desc12, DialogModes.NO );

// create directory called export
var myExportDir = "export"
var myDirectoryName = srcDoc.path + "/" + myExportDir;
var myDirectory = new Folder(myDirectoryName);
if(!myDirectory.exists) myDirectory.create();

// define the array to hold the sizes of the shrunk images
var reSizeArr = [
   [125,  70,  ResampleMethod.BICUBIC],
   [640,  360, ResampleMethod.BICUBIC],
   [320,  180, ResampleMethod.BICUBIC],
   [1005, 565, ResampleMethod.BICUBIC],
      ]

for (var i=0; i<reSizeArr.length; i++)
   {
   var shrinkWidth =  reSizeArr [i][0];
   var shrinkHeight = reSizeArr [i][1];
   var mySaveName = shrinkWidth + "x" + shrinkHeight;
   var resizeMethod = reSizeArr [i][2];

   // duplicate image into new document
   // =======================================================
   var id428 = charIDToTypeID( "Dplc" );
   var desc92 = new ActionDescriptor();
   var id429 = charIDToTypeID( "null" );
   var ref27 = new ActionReference();
   var id430 = charIDToTypeID( "Dcmn" );
   var id431 = charIDToTypeID( "Ordn" );
   var id432 = charIDToTypeID( "Frst" );
   ref27.putEnumerated( id430, id431, id432 );
   desc92.putReference( id429, ref27 );
   var id433 = charIDToTypeID( "Nm  " );
   desc92.putString( id433, mySaveName );
   executeAction( id428, desc92, DialogModes.NO );

   // resize image
   activeDocument.resizeImage(shrinkWidth, shrinkHeight, resizeRes, resizeMethod);

   // set to 256 cols
   var id111 = charIDToTypeID( "CnvM" );
   var desc23 = new ActionDescriptor();
   var id112 = charIDToTypeID( "T   " );
   var desc24 = new ActionDescriptor();
   var id113 = charIDToTypeID( "Plt " );
   var id114 = charIDToTypeID( "ClrP" );
   var id115 = charIDToTypeID( "Exct" );
   desc24.putEnumerated( id113, id114, id115 );
   var id116 = charIDToTypeID( "FrcC" );
   var id117 = charIDToTypeID( "FrcC" );
   var id118 = charIDToTypeID( "None" );
   desc24.putEnumerated( id116, id117, id118 );
   var id119 = charIDToTypeID( "Trns" );
   desc24.putBoolean( id119, false );
   var id120 = charIDToTypeID( "IndC" );
   desc23.putObject( id112, id120, desc24 );
   executeAction( id111, desc23, DialogModes.NO );

   // Set filePath and fileName to source path
   filePath = srcDoc.path + "/" + myExportDir + "/" + mySaveName  + ".gif";

   // save out the image
   var gifFile = new File(filePath);
   gifSaveOptions = new GIFSaveOptions();
   gifSaveOptions.colors = 256;
   gifSaveOptions.dither = Dither.NONE;
   gifSaveOptions.matte = MatteType.NONE;
   gifSaveOptions.preserveExactColors = 0;
   gifSaveOptions.transparency = 1;

   activeDocument.saveAs(gifFile, gifSaveOptions, false, Extension.LOWERCASE);

   // close that saved gif
    app.activeDocument.close()
   } 

   //close without saving
   app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);