Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Save for web scripting

Community Beginner ,
Sep 29, 2020 Sep 29, 2020

Does anyone have a readily available script for saving for web as optimised jpegs? i cant find one anywhere online, still learning javascript so would like to see how its done and then play around with it myself for a better understanding.

I've also looked in the photoshop documentation and cant find anywhere to script 'optimize to file size'? ideally i would like the quality to differ as i would want the max file size to be 600kb for example. is this possible? its possible if i manually saveforweb?

TOPICS
Actions and scripting
764
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Beginner ,
Sep 29, 2020 Sep 29, 2020

https://community.adobe.com/t5/photoshop/photoshop-script-for-faster-save-for-web/td-p/10735828?page...

update, just found this and i think this is what im after in regards to the file saving, no luck finding any info on the file size optimisation though!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 29, 2020 Sep 29, 2020

»to script 'optimize to file size'?«

What exactly do you mean? 

 

»I've also looked in the photoshop documentation«

Did you find this page? 

Screenshot 2020-09-29 at 09.32.55.pngexpand image

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 29, 2020 Sep 29, 2020

hi!
yes thats the page i was after, so in the saveforweb dialog box, you can save the image at a specified file size, this obviously determines the quality (0,100). The scripts intention is to save maybe 150-200 images per day and they cant really be above 700kb each as theyre used for ecom purposes.

Screenshot 2020-09-29 at 08.46.48.pngexpand image

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 29, 2020 Sep 29, 2020

That’s not in the DOM, as dar as I can tell. 

Does it produce identifyable AM code with ScripitingListerner.plugin? 

Otherwiese the Script would probably need to itterate through quality settings, check the size until it hits an acceptable one. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 29, 2020 Sep 29, 2020

I've not used that plugin, I'll have a go and see what it brings up. thank you for the replies!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 29, 2020 Sep 29, 2020

You’ll

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 29, 2020 Sep 29, 2020

Sorry, mis-click on the previous post … 

 

You’ll need that plugin when the DOM doesn't suffice. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 29, 2020 Sep 29, 2020

Perhaps something like this?

 

EDIT: Link removed as it is now invalid

 
mindfulretouch.com/the-course/saving/saving-quality
 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 29, 2020 Sep 29, 2020

unbelievable man! thank you haha, ill give this a go and see if it works the way i need it to. no idea how you found that!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 10, 2025 May 10, 2025

this link now leads to a suspicious website.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2025 May 10, 2025
LATEST
quote

this link now leads to a suspicious website.


By Nishant.Kumar.2906


Thank you for the bump, yes, the site is now down and the original link is now redirecting to rubbish.

 

Here is the code from the original link:

 

var doc = app.activeDocument;
var filename = doc.name;
var foldername = doc.path.name;
var filepath = doc.path;
var parentfilepath = doc.path.parent
var jpegQuality = 70; // desired quality
var maxfilesize = 512000; // max size in bytes
var dec = 5; // decreasing step
var minimumqual = 50; //minumum desired quality
savefolder = new Folder(filepath + '/BATCH/');
savefolder.create();
saveFile = new File(savefolder + '/' + filename.split('.').slice(0, -1).join('.') + ".jpg");
doc.flatten();
doc.pathItems.removeAll();
doc.channels.removeAll();

function savebatchweb(saveFile, jpegQuality) {
    var sfwOptions = new ExportOptionsSaveForWeb();
    sfwOptions.format = SaveDocumentType.JPEG;
    sfwOptions.includeProfile = true;
    sfwOptions.interlaced = 0;
    sfwOptions.optimized = true;
    sfwOptions.quality = jpegQuality;
    doc.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);
}
savebatchweb(saveFile, jpegQuality);
while (saveFile.length > maxfilesize) {
    jpegQuality = jpegQuality – dec;
    saveFile = new File(saveFile);
    saveFile.remove();
    savebatchweb(saveFile, jpegQuality);
    if (jpegQuality <= minimumqual) {
        break
    }
}
doc.close(SaveOptions.DONOTSAVECHANGES); //closes file

 

or

 

https://codebybrett.github.io/savesmalljpeg/

 

or

 

 

Going back to the original post, this isn't covered in standard DOM scripting, nor is it available to the scripting listner plug-in, so AFAIK, the AM scripting alternative isn't possible.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines