title: I have a script to resize an image. Is there anyway to have it output 5 images?
body: <pre><code>doc = app.activeDocument;  
  
  // these are our values for the END RESULT width and height (in pixels) of our image
  var fWidth = 1313;
  var fHeight = 1750;
  
  // do the resizing.  if height &gt; width (portrait-mode) resize based on height.  otherwise, resize based on width
  if (doc.height &gt; doc.width) {
      doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);
  }
  else {
      doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
  }
  
  // Makes the default background white
  var white = new SolidColor(); 
  white.rgb.hexValue = "FFFFFF";
  app.backgroundColor = white;
  
  // 2012, use it at your own risk;
  
  #target photoshop
  
  if (app.documents.length &gt; 0) {
  var myDocument = app.activeDocument;
  var originalRulerUnits = app.preferences.rulerUnits;
  app.preferences.rulerUnits = Units.PERCENT;
  myDocument.resizeCanvas(myDocument.width + 40, myDocument.height + 40, AnchorPosition.MIDDLECENTER)
  app.preferences.rulerUnits = originalRulerUnits;
  };
  
  // our web export options
  var options = new ExportOptionsSaveForWeb();
  options.quality = 70;
  options.format = SaveDocumentType.JPEG;
  options.optimized = true;
  
  var newName = 'test'+doc.name+'.jpg';
  
  doc.exportDocument(File(doc.path+'/'+newName),ExportType.SAVEFORWEB,options);
  </code></pre>
  
  <p>I want to be able to generate 5 images with 5 different sizes with the same script. Is it just as simple as repeating my code multiple times, or do i need to reset some variables in between? </p>
  
  <p>When I try just duplicating my code and changing the output file name and the sizes, it does it but my canvas size doesn't reset and change based off the current image size. It just keeps getting bigger. Is there anyway to make the canvas size resize based on that current image size?</p>
  
  <pre><code>var sizes = [
  {
      width: 1531,
      height: 1948
  },
  {
      width: 1303,
      height: 1954
  },  
  {
      width: 1066,
      height: 1909
  }
   ];
  doc = app.activeDocument;
  // looping through all the sizes
  for (var i = 0; i &lt; sizes.length; i++)
  {
      var cloneDoc = doc.duplicate(); // duplicates current document
      resizeAndSave(sizes[i].width, sizes[i].height); // passes width and height of sizes to function with your code
      cloneDoc.close(SaveOptions.DONOTSAVECHANGES); // closes the clone
      activeDocument = doc; // making sure that foremost document is the original doc
  }
  
  function resizeAndSave(fWidth, fHeight)
  {
      //your code
  
  
  // get a reference to the current (active) document and store it in a variable named "doc"
  
  
  
  
  // these are our values for the END RESULT width and height (in pixels) of our image
  //var fWidth = 1313;
  //var fHeight = 1750;
  
  // do the resizing.  if height &gt; width (portrait-mode) resize based on height.  otherwise, resize based on width
  activeDocument = doc;
  if (doc.height &gt; doc.width) {
      doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);
  }
  else {
      doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
  }
  
  // Makes the default background white
  var white = new SolidColor(); 
  white.rgb.hexValue = "FFFFFF";
  app.backgroundColor = white;
  
  // 2012, use it at your own risk;
  
  #target photoshop
  
  if (app.documents.length &gt; 0) {
  
  var myDocument = app.activeDocument;
  
  var originalRulerUnits = app.preferences.rulerUnits;
  
  app.preferences.rulerUnits = Units.PERCENT;
  
  myDocument.resizeCanvas(myDocument.width + 40, myDocument.height + 40, AnchorPosition.MIDDLECENTER)
  
  app.preferences.rulerUnits = originalRulerUnits;
  
  };
  
  // our web export options
  
  var options = new ExportOptionsSaveForWeb();
  options.quality = 70;
  options.format = SaveDocumentType.JPEG;
  options.optimized = true;
  
  var newName = 'test'+doc.name+'.jpg';
  
  doc.exportDocument(File(doc.path+'/'+newName),ExportType.SAVEFORWEB,options);
  
  };
  
  </code></pre>