Skip to main content
Participating Frequently
May 12, 2016
Question

Save For Web Image Size settings

  • May 12, 2016
  • 2 replies
  • 3851 views

Hi folks,

This is currently driving me mad.

Is there any way of accessing the Image options in Save For Web via script????

I need to be able to manipulate the following:

Image Size Percent:

Image Size Quality:

I've looked everywhere, trawled through the api and can't find any information.

My workaround is to use an action to resize the image and then run a script to ExportOptionsSaveForWeb() but this always results in a larger file size and, for some unknown reason, an image that is 1px up and to the left.

I do not get this issue when running this same process manually with exactly the same settings.

Any help?

This topic has been closed for replies.

2 replies

Known Participant
August 10, 2016

IMO Photoshops' image compression tools aren't very good, maybe you can achieve something externally. I would recommend exporting as a high quality jpg (or png if you need transparency or are working with flat colors) at the exact resolution you need them to appear, then using a tool like https://tinypng.com/ or WP- smush. You'll end up with smaller images that look better than what photoshop can achieve.

JJMack
Community Expert
Community Expert
May 12, 2016

File size is not predictable. How well an image will compress depends on how much fine detail you have for an image   An image x pixels wide by y pixels high  saves as a high quality jpeg image can be as small as 200KB to as large as 7MB depends on image content.

JJMack
Participating Frequently
May 12, 2016

Hi JJMack,

For the images I'm working on we have a master image created from a manual export.

I localise these images x 50. If I export each 1x version manually it is always around the same size in bytes.

Trying to script this exact process I always end up with an image that's a large files size and has a slight deviation in layout.

The only thing that changes from using scripts and using the manual process is changing the image size to 50% in the Save For Web window and that appears to be messing things up hence why I want to know if this can be accessed using javascript to run some tests and hopefully export images of the same quality, layout and file size.

JJMack
Community Expert
Community Expert
May 12, 2016

Manual process.

  1. Open 2x image
  2. SaveForWeb
  3. Change Image Size to 50%
  4. Save.

Current Scripted process:

  1. Run 1x Script

var filePath = activeDocument.fullName.fsName

var saved = false;

var curDoc = activeDocument;

var heightOK = false;

var widthOK = false;

if (actionExists("50%", "Apple_PSD") && actionExists("Make_Edit", "Prep")) {

  if ( isEven(curDoc.height) ){

       heightOK = true;

  } else {

       heightOK = false;

  }

  if ( isEven(curDoc.width) ){

       widthOK = true;

  } else {

       widthOK = false;

  }

  if ( heightOK && widthOK ) {

  doAction("Make_Edit", "Prep");

  doAction("50%", "Apple_PSD"); 'This action is just, image Width and Height = 50%, Interpolation = Bicubic

  var newPath = filePath.split("_2x");

  newPath = newPath[0] + newPath[1];

  var fileType = filePath.split("_2x.");

  fileType = fileType[1];

  switch(fileType){

  case "jpg":

  saveFile = new File(newPath);

  saveOptions = new ExportOptionsSaveForWeb();

  saveOptions.format = SaveDocumentType.JPEG

  saveOptions.optimized = false;

  saveOptions.quality = 78;

  activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, saveOptions);

  saved = true;

  break;

  case "gif":

  saveFile = new File(newPath);

  saveOptions = new GIFSaveOptions();

  saveOptions.colors = 256;

  saveOptions.dither = Dither.NONE;

  saveOptions.matte = MatteType.WHITE;

  saveOptions.preserveExactColors = 0;

  saveOptions.transparency = 1;

  saveOptions.interlaced = 0;

  break;

  case "png":

  saveFile = new File(newPath);

  saveOptions = new ExportOptionsSaveForWeb();

  saveOptions.format = SaveDocumentType.PNG;

  saveOptions.PNG8 = false;

  saveOptions.quality = 100;

  activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, saveOptions);

  saved = true;

  break;

  }

  if (saved == false) { curDoc.saveAs(saveFile, saveOptions, true, Extension.LOWERCASE); }

  activeDocument.close(SaveOptions.DONOTSAVECHANGES);

  } else {

  if ( heightOK == false ){

  alert("Height of image is incorrect - must be an even number");

  }

  if ( widthOK == false  ){

  alert("Width of image is incorrect - must be an even number");

  }

  }

}

function actionExists( actionName, setName ){

   var res = false;

   try{

      var ref = new ActionReference();

      ref.putName( charIDToTypeID( 'Actn' ), actionName );

      ref.putName( charIDToTypeID( "ASet" ), setName );

      executeActionGet( ref );

      res = true;

   }catch(e){}

   return res;

}

function isEven(value) {

  if (value%2 == 0)

  return true;

  else

  return false;

}


nickc97991501 wrote:

Manual process.

  1. Open 2x image          Is 2x a process or is the image  2x the size you need
  2. SaveForWeb             If 2x is not a process why are you saving what you just opened?
  3. Change Image Size to 50%  Resampling or changing image's Resolution?
  4. Save.

Current Scripted process:

  1. Run 1x Script

The two actions save them as text files and post. IMO you are also asking for problems in the future using two outside actions which are in different action sets.

JJMack