Using JavaScript scripting in Adobe Photoshop,how to save some layers as same size?
I have script to save some layers. But it's save as original开发者_JAVA技巧 layer size.
I want to save layers as same costom size.
Do you know or have a script like this?
Here is some code that I wrote some time ago:
var folder = new Folder(SOME_PATH); var files = folder.getFiles();
for (var i = 0; i < files.length; i++)
{
app.load(files[i]);
var docRef = app.activeDocument;
resize(docRef);
var options = new ExportOptionsSaveForWeb();
var a = files[i].name.split('.');
var filename = a[0] + '.' + ( a[1].toLowerCase() != 'jpg' ? a[1] + '.' : '' ) + 'jpg';
var JPEGFile = new File( SOME_PATH + filename );
options.quality = 70;
options.format = SaveDocumentType.JPEG; //I Suppose you might want to save to some other format though
docRef.exportDocument(JPEGFile, ExportType.SAVEFORWEB, options);
docRef.close(SaveOptions.DONOTSAVECHANGES);
}
function resize(doc)
{
var TARGET = SOME_TARGET;
var dist = Math.max(doc.width.as('px'), doc.height.as('px'));
if(dist > 0)
{
var ratio = (TARGET / dist);
var newWidth = new UnitValue(doc.width.as('px') * ratio, 'px')
var newHeight = new UnitValue(doc.height.as('px') * ratio, 'px')
doc.resizeImage(newWidth, newHeight);
//alert('width:' + doc.width * ratio + ' height:' + doc.height * ratio);
}
}
精彩评论