2010-06-16 13 views

Répondre

0

Voici un code que j'ai écrit il y a quelque temps:

dossier var = new dossier (de SOME_PATH); var fichiers = dossier.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); 
} 

}