3 Replies Latest reply on Feb 18, 2016 9:44 AM by pixxxel schubser

    Set Opacity of an image loaded into Photoshop

    jameel flex

      Hi,

       

      I am trying to load an image into Photoshop and set it's opacity to 60% but it's not working.

      I even tried to set the layer opacity but couldn't get it work.

      Please suggest where I am doing the mistake.

       

      Below is my code.

       

      var fileRef = new File(imagepath);

        var curRefDoc = app.open(fileRef);

        var curw = curRefDoc.width;

        var curh = curRefDoc.height;

        

          var resW;

          var resH;

        

          var scw =  imgObj.wi/curw;

          var sch =  imgObj.hi/curh;

       

       

          var scale ;

          if(scw > sch)

              scale = scw;

          else

              scale = sch;   

        

          resW = curw * scale;

          resH = curh * scale;

       

       

        if(imgObj.isAdjustImage == "true")

        {

        resW = resW * parseFloat (imgObj.scaleOrg);

        resH = resH * parseFloat (imgObj.scaleOrg);

        }

       

       

      curRefDoc.selection.selectAll();

       

       

        curRefDoc.resizeImage( resW,resH );

       

        if(imgObj.isAdjustImage == "true"){

        curRefDoc.rotateCanvas(Number(imgObj.imgRotation));

        if(imgObj.isImgHFlipped == "true" && imgObj.isImgVFlipped == "false")

             curRefDoc.flipCanvas(Direction.HORIZONTAL);

        if(imgObj.isImgVFlipped == "true" && imgObj.isImgHFlipped == "false")

             curRefDoc.flipCanvas(Direction.VERTICAL);

        curRefDoc.activeLayer.opacity = 60;

        }

       

       

        /**

        * Added_SB(11032011):

        * New selection / copy / paste logic for opened image.

        */

        var DPI = changedDPI;

        var offsetX = (imgObj.moveX * DPI) / 72;

        var offsetY = (imgObj.moveY * DPI) / 72;

        var iW = imgObj.innerImageWidth;

        var iH = imgObj.innerImageHeight;

        var sL = Math.abs(offsetX);

        var sT = Math.abs(offsetY);

        var sR = Number(imgObj.wi) - (offsetX>0 ? sL : -sL);

        var sB = Number(imgObj.hi) - (offsetY>0 ? sT : -sT);

       

       

       

        var selectionArray = Array (

        Array(offsetX>0 ? 0 : sL, offsetY>0 ? 0 : sT),

        Array(sR, offsetY>0 ? 0 : sT),

        Array(sR, sB),

        Array(offsetX>0 ? 0 : sL, sB));

       

       

       

       

        curRefDoc.selection.select (selectionArray, SelectionType.EXTEND, 0, false);

        curRefDoc.selection.copy();

        curRefDoc.close(SaveOptions.DONOTSAVECHANGES);

       

       

        var curDoc = getCurDoc(mainAppName);

        app.activeDocument = curDoc;

        curDoc.paste();