I need to set the maximum compression that does not exceed 370KB.
Hello, all.
I'm a novice when it comes to scripts in Photoshop, but I'm really coming to the conclusion that this is the only way to automate the actions I need to do, whithout having to do it one-by-one.
Is it possible to write a Script to automatically choose the option (and settings) to "Optimize to file size" in the "Save for Web" dialog?
Is it also possible to save the file in the document's original folder?
I only have a restriction of size (370Kb) for thosefiles, and I would like to save all of them, in each document original folder, with the best possible quality within that size constraint.
I Have this script, but have any problem, do not save in the same folder:
// MAC Finder ou WINDOWS Explorer, on autorise le double clic et on fait passer Photoshop au 1er plan
#target photoshop
app.bringToFront();
// We shall have to work in pixels
var regleUnite = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// Variables declaration
var sizeMax = 360; // Kb
sizeMax *=1024; // Conversion to bytes
var fileName = new File();
var qlt = 100; // Quality
var sizeImg=1000000; // We choose a great value
var docRef = activeDocument;
var docName = docRef.name;
var docName = docName.substring( 0, docName.indexOf('.') );
var imgWidth = docRef.width;
var imgHeight = docRef.height;
// The image is resized
docRef.resizeImage(imgWidth, imgHeight);
var exportOptionsSaveForWeb = new ExportOptionsSaveForWeb();
exportOptionsSaveForWeb.format = SaveDocumentType.JPEG;
exportOptionsSaveForWeb.includeProfile = true;
while (sizeImg > sizeMax)
{
fileName = new File(docRef.path + docName+qlt+".jpg");
exportOptionsSaveForWeb.quality = qlt;
docRef.exportDocument (fileName, ExportType.SAVEFORWEB, exportOptionsSaveForWeb);
qlt-=1;
sizeImg = fileName.length;
if (sizeImg>sizeMax)
{
fileName.remove();
}
}
