Last active
July 18, 2017 18:53
-
-
Save DareWreck/8444593 to your computer and use it in GitHub Desktop.
Photoshop save image as jpg in image origin folder with appended file name for use in conjunction with an action/droplet combo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var docRef = app.activeDocument; | |
| function ExportJpg(path, filename, qual) | |
| { | |
| try | |
| { | |
| var options = new ExportOptionsSaveForWeb(); | |
| jpgFile = new File( path + "\\" + filename ); | |
| options.quality = qual; // Start with highest quality (biggest file). | |
| options.format = SaveDocumentType.JPEG; // Or it'll default to GIF. | |
| docRef.exportDocument(jpgFile, ExportType.SAVEFORWEB, options); | |
| } | |
| catch (e) | |
| { // display error | |
| alert("Error encountered when saving the image! \r\r" + e); | |
| return; // quit | |
| } | |
| }; | |
| function main() | |
| { | |
| try | |
| { | |
| var docRef = app.activeDocument; | |
| // for (var key in docRef) { | |
| // alert(key + ': ' + docRef[key]); | |
| // } | |
| // var fname = docRef.name.split("."); // splits at first sign of "." | |
| // var fname = fname[0]; | |
| var fname = docRef.name.substring(0, docRef.name.lastIndexOf(".")); // will split before the LAST "." | |
| ExportJpg(app.activeDocument.fullName.parent.fsName, fname + "-optimized.jpg", 70); | |
| } | |
| catch (e) | |
| { // display error | |
| alert("Error encountered when saving the image! \r\r" + e); | |
| return; // quit | |
| } | |
| }; | |
| // execute script | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you please help me scripting a Save As animated GIF with "loop forever" and name, as a layer name?
I have the script blow that saves JPG using a layer name. It works great.
I am trying to update this script so, that it would save animated GIF with "loop forever" option.
It would be just awesome if there is a possibility to set in the script quantity of GIF's colors (64, 128, 256), Transparency, Dithering and other parameters.
Any help would be greatly appreciated!
#target photoshop
main();
function main(){
if(!documents.length) return;
try{
var Path= activeDocument.path;
}catch(e){var Path = "~/desktop";}
var Name = decodeURI(app.activeDocument.name).replace(/.[^\.]+$/, '');
var layerName = app.activeDocument.activeLayer.name.replace(/[:/\*?"<>|]/g, "_");
var saveFile= new File(Path + "/" + Name + "-" + layerName + ".jpg");
SaveForWeb(saveFile,80);
}
function SaveForWeb(saveFile,jpegQuality) {
var sfwOptions = new ExportOptionsSaveForWeb();
sfwOptions.format = SaveDocumentType.JPEG;
sfwOptions.includeProfile = false;
sfwOptions.interlaced = 0;
sfwOptions.optimized = true;
sfwOptions.quality = jpegQuality;
activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);
}