armur 0 Newbie Poster

Hi,

I run an online shop selling T Shirts and we often need to produce tons of T Shirt mockup images in Photoshop. We basically enable the layer for different T Shirt colours, Save Mockup As a JPG file and then repeat the same process for all the other colours. Since it was super boring, super repetitive and time consuming to do this, I put together this neat Photoshop script to do the whole job with a single click.

//Cobbled together from:
//http://feedback.photoshop.com/photoshop_family/topics/quick_save_as
//http://www.polycount.com/forum/showthread.php?t=85425

#target photoshop;

if (app.documents.length > 0) {
  var thedoc = app.activeDocument;

  var docName = thedoc.name;
  if (docName.indexOf(".") != -1) {
    var basename = docName.match(/(.*)\.[^\.]+$/)[1];
  } else {
    var basename = docName;
  }

  //getting the location, if unsaved save to desktop;
  try {
    var docPath = thedoc.path;
  } catch (e) {
    var docPath = "~/Desktop";
  }

  var jpegOptions = new JPEGSaveOptions();
  jpegOptions.quality = 12;
  jpegOptions.embedColorProfile = true;
  jpegOptions.matte = MatteType.NONE;

  //Hide all layers

  for(var i=0;i<thedoc.layers.length;i++){

      var currentLayer = app.activeDocument.layers[i];

      currentLayer.visible = false;  

  }

  //Save front mockups

  for(i=0;i<20;i+=2){

      var currentLayer = app.activeDocument.layers[i];

      currentLayer.visible = true;
      app.activeDocument.layers[i + 1].visible = true;

      var filename = docPath + '/' + basename + "-" + app.activeDocument.layers[i + 1].name + '.jpg';

      thedoc.saveAs((new File(filename)), jpegOptions, true);

      currentLayer.visible = false;
      app.activeDocument.layers[i + 1].visible = false;

  }

  app.activeDocument.layers[0].visible = true;
  app.activeDocument.layers[1].visible = true;

  alert("Variation Mockups Generated")

};

It works flawlessly and I'm super happy with it.

Next up, I have been trying to make this code generate WEBP images instead of JPG so that the file sizes when uploaded to the website are super small without noticeable loss in image quality. I know that it has something to do with changing the SaveAsOptions lines, but I can't seem to get it right. I use a plugin to enable WEBP support in Photoshop. Can somebody help me out please?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.