3 Replies Latest reply on Oct 6, 2016 4:55 AM by c.pfaffenbichler

    Open all pdf files in folder and save as resized jpgs in other folder

    heresha93876846 Level 1

      I have a script that checks if a image is wider than 250px and if it is taller than 300px and if any of these statements are true it should resize them to fit within both of these values. Then it should save them as jpgs with the extension large to the filename in a folder named large. However I dont know how to make photoshop open all files in a given folder and execute the script, also I dont know how to export them correctly, photoshop stops when it tries to export.

      Here is my code:

       

      // get a reference to the current (active) document and store it in a variable named "doc"
      doc
      = app.activeDocument; 

      // change the color mode to RGB. Important for resizing GIFs with indexed colors, to get better results
      doc
      .changeMode(ChangeMode.RGB); 

      // these are our values for the END RESULT width and height (in pixels) of our image
      var fWidth = 250;
      var fHeight = 300;

      // do the resizing. if height > width (portrait-mode) resize based on height. otherwise, resize based on width
      if (doc.height > 300) { doc.resizeImage(null,UnitValue(fHeight,"300"),null,ResampleMethod.BICUBIC); }
      else if (doc.width > 250) {  doc.resizeImage(null,UnitValue(fWidth,"250"),null,ResampleMethod.BICUBIC); }


      // Makes the default background white
      var white = new SolidColor();
      white
      .rgb.hexValue = "FFFFFF";
      app
      .backgroundColor = white;

      // Convert the canvas size as informed above for the END RESULT app.activeDocument.resizeCanvas(UnitValue(fWidth,"px"),UnitValue(fHeight,"px"));

      // our web export options
      var options = new ExportOptionsSaveForWeb();
      options
      .quality = 70;
      options
      .format = SaveDocumentType.JPEG;
      options
      .optimized = true;

      var newName = 'web-'+doc.name+'.jpg';

      doc
      .exportDocument(File(doc.path+'/images/'+newName);