Copy link to clipboard
Copied
#target photoshop
main();
function main(){
if(!documents.length) return;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = app.activeDocument;
var Name = doc.name.replace(/\.[^\.]+$/, '');
var Path = decodeURI(doc.path);
doc.convertProfile( 'sRGB IEC61966-2.1', Intent.RELATIVECOLORIMETRIC, true, true );
createNamedSnapshot("Snap 1");
doc.convertProfile("Working CMYK", Intent.RELATIVECOLORIMETRIC, true, true, false);
doc.resizeImage(1500, undefined, 300, ResampleMethod.BICUBIC);
var outFolder = Folder(Path +"/TIFF");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+"_1500px.tif");
SaveTIFF(saveFile);
revertNamedSnapshot("Snap 1");
doc.resizeImage(1500, undefined, 300, ResampleMethod.BICUBIC);
outFolder = Folder(Path +"/PNG");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+".png");
SavePNG(saveFile);
revertNamedSnapshot("Snap 1");
doc.resizeImage(500, undefined, 72, ResampleMethod.BICUBIC);
outFolder = Folder(Path +"/500px");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+"_500px.jpg");
SaveJPEG(saveFile,8);
revertNamedSnapshot("Snap 1");
doc.resizeImage(150, undefined, 72, ResampleMethod.BICUBIC);
outFolder = Folder(Path +"/150px");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+"_150px.jpg");
SaveJPEG(saveFile,8);
revertNamedSnapshot("Snap 1");
doc.resizeImage(100, undefined, 72, ResampleMethod.BICUBIC);
outFolder = Folder(Path +"/gif");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+"_100px.gif");
SaveGIF(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = startRulerUnits;
if(documents.length)
var doc = activeDocument;
var Width = doc.width.as('px');
var Height = doc.height.as('px');
var Max = Math.max(Width,Height);
var Min = Math.min(Width,Height);
var White = new SolidColor;
White.rgb.hexValue = 'ffffff';
backgroundColor = White;
doc.resizeCanvas(new UnitValue(Max,"px"),new UnitValue(Max,"px"),AnchorPosition.MIDDLECENTER);
doc.resizeImage(new UnitValue(Min,"px"), undefined, undefined, ResampleMethod.BICUBIC);
doc.resizeImage(1000, undefined, 300, ResampleMethod.BICUBIC);
var outFolder = Folder(Path +"/THD");
var saveFile = File(outFolder +"/"+Name+"_THD.jpg");
SaveJPEG(saveFile,8);
revertNamedSnapshot("Snap 1");
}
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; //1-12
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
}
function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(new File(saveFile), tiffSaveOptions, true, Extension.LOWERCASE);
}
function SavePNG(saveFile){
pngSaveOptions = new PNGSaveOptions();
doc.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}
function SaveGIF(saveFile){
gifSaveOptions = new ExportOptionsSaveForWeb();
gifSaveOptions.Colors = 256;
gifSaveOptions.dither = Dither.NONE;
gifSaveOptions.quality = 0;
gifSaveOptions.matte = MatteType.SEMIGRAY;
doc.exportDocument(gifFile, ExportType.SAVEFORWEB, gifSaveOptions, Extension.LOWERCASE);
}
function createNamedSnapshot(name) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( charIDToTypeID('SnpS') );
desc.putReference( charIDToTypeID('null'), ref );
var ref1 = new ActionReference();
ref1.putProperty( charIDToTypeID('HstS'), charIDToTypeID('CrnH') );
desc.putReference( charIDToTypeID('From'), ref1 );
desc.putString( charIDToTypeID('Nm '), name );
desc.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('HstS'), charIDToTypeID('FllD') );
}
function revertNamedSnapshot(name) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( charIDToTypeID('SnpS'), name );
desc.putReference( charIDToTypeID('null'), ref );
executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
}
Copy link to clipboard
Copied
Does this works for you?
function SavePNG(saveFile){ // save4WebPNG8(saveFile)
var pngSaveOptions = new ExportOptionsSaveForWeb;
pngSaveOptions.format = SaveDocumentType.PNG
pngSaveOptions.PNG8 = true;
//pngSaveOptions.transparency = false;
//pngSaveOptions.interlaced = false;
doc.exportDocument(saveFile,ExportType.SAVEFORWEB,pngSaveOptions, Extension.LOWERCASE);
}
Copy link to clipboard
Copied
Thank you the script is working!
Sent from my Verizon Wireless 4G LTE DROID
Copy link to clipboard
Copied
There were several problems, the main problem was that the snapshot was not getting created, please try this now...
#target photoshop
main();
function main(){
if(!documents.length) return;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = app.activeDocument;
var Name = doc.name.replace(/\.[^\.]+$/, '');
var Path = decodeURI(doc.path);
doc.convertProfile( 'sRGB IEC61966-2.1', Intent.RELATIVECOLORIMETRIC, true, true );
createNamedSnapshot("Snap 1");
doc.convertProfile("Working CMYK", Intent.RELATIVECOLORIMETRIC, true, true, false);
doc.resizeImage(1500, undefined, 300, ResampleMethod.BICUBIC);
var outFolder = Folder(Path +"/TIFF");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+"_1500px.tif");
SaveTIFF(saveFile);
revertNamedSnapshot("Snap 1");
doc.resizeImage(1500, undefined, 300, ResampleMethod.BICUBIC);
outFolder = Folder(Path +"/PNG");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+".png");
SavePNG(saveFile);
revertNamedSnapshot("Snap 1");
doc.resizeImage(500, undefined, 72, ResampleMethod.BICUBIC);
outFolder = Folder(Path +"/500px");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+"_500px.jpg");
SaveJPEG(saveFile,8);
revertNamedSnapshot("Snap 1");
doc.resizeImage(150, undefined, 72, ResampleMethod.BICUBIC);
outFolder = Folder(Path +"/150px");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+"_150px.jpg");
SaveJPEG(saveFile,8);
revertNamedSnapshot("Snap 1");
doc.resizeImage(100, undefined, 72, ResampleMethod.BICUBIC);
outFolder = Folder(Path +"/gif");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+"_100px.gif");
SaveGIF(saveFile);
revertNamedSnapshot("Snap 1");
var Width = doc.width.as('px');
var Height = doc.height.as('px');
var Max = Math.max(Width,Height);
var Min = Math.min(Width,Height);
var White = new SolidColor;
White.rgb.hexValue = 'ffffff';
backgroundColor = White;
doc.resizeCanvas(new UnitValue(Max,"px"),new UnitValue(Max,"px"),AnchorPosition.MIDDLECENTER);
doc.resizeImage(new UnitValue(Min,"px"), undefined, undefined, ResampleMethod.BICUBIC);
doc.resizeImage(1000, undefined, 300, ResampleMethod.BICUBIC);
var outFolder = Folder(Path +"/THD");
var saveFile = File(outFolder +"/"+Name+"_THD.jpg");
if(!outFolder.exists) outFolder.create();
SaveJPEG(saveFile,8);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = startRulerUnits;
}
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
}
function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(new File(saveFile), tiffSaveOptions, true, Extension.LOWERCASE);
}
function SavePNG(saveFile){
pngSaveOptions = new PNGSaveOptions();
activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}
function SaveGIF(saveFile){
gifSaveOptions = new ExportOptionsSaveForWeb();
gifSaveOptions.Colors = 256;
gifSaveOptions.dither = Dither.NONE;
gifSaveOptions.quality = 100;
gifSaveOptions.matte = MatteType.SEMIGRAY;
activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, gifSaveOptions, Extension.LOWERCASE);
}
function createNamedSnapshot(name) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( charIDToTypeID('SnpS') );
desc.putReference( charIDToTypeID('null'), ref );
var ref1 = new ActionReference();
ref1.putProperty( charIDToTypeID('HstS'), charIDToTypeID('CrnH') );
desc.putReference( charIDToTypeID('From'), ref1 );
desc.putString( charIDToTypeID('Nm '), name );
desc.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('HstS'), charIDToTypeID('FllD') );
executeAction( charIDToTypeID('Mk '), desc, DialogModes.NO );
}
function revertNamedSnapshot(name) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( charIDToTypeID('SnpS'), name );
desc.putReference( charIDToTypeID('null'), ref );
executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
}
Copy link to clipboard
Copied
Thank you... I appreciate your help!
Sent from my Verizon Wireless 4G LTE DROID