【问题标题】:Photoshop Script - create new fill layer behind imagePhotoshop 脚本 - 在图像后面创建新的填充层
【发布时间】:2017-07-13 20:33:13
【问题描述】:

我目前遇到一个问题,我正在创建一些图像并且需要在当前图像后面创建一个填充层。目前,新图层位于图像顶部,这给了我一个白色文件。这个新的白色层必须是最后一层,这样图像文件才能位于填充层之上。

代码如下

var NoImages = File.openDialog("Select your logo file", false);

if (NoImages !== null) { 
    var doc = open(NoImages, OpenDocumentType.PNG.JPEG); // Open PNG file

    if (doc == null) {
      throw "Something is wrong with the file.";
    }

    var startState = doc.activeHistoryState;       // save for undo
    var initialPrefs = app.preferences.rulerUnits; // will restore at end
    app.preferences.rulerUnits = Units.PIXELS;     // use pixels

    // Folder selection dialog
    var destFolder = Folder.selectDialog( "Choose an output folder");

    if (destFolder == null) {
      // User canceled, just exit
      throw "";
    }

    // Save icons in PNG using Save for Web.
    var sfw = new ExportOptionsSaveForWeb();
    sfw.format = SaveDocumentType.PNG;
    sfw.PNG8 = false; // use PNG-24
    sfw.transparency = true;
    doc.info = null;  // delete metadata

   var no_images = [
      {"name": "no-image-1-1", "width":1170, "height":1170},
      {"name": "no-image-2-3", "width":779, "height":1170},
      {"name": "no-image-3-2", "width":1170, "height":779},
      {"name": "no-image-3-4", "width":879, "height":1170},
      {"name": "no-image-4-3", "width":1170, "height":879},
      {"name": "no-image-7-2", "width":1170, "height":334},
      {"name": "no-image-9-3", "width":1170, "height":391},
      {"name": "no-image-11-5", "width":1170, "height":532},
      {"name": "no-image-16-9", "width":1170, "height":658}
    ];

    var no_image;
    for (i = 0; i < no_images.length; i++)  {
        no_image = no_images[i];
        doc.resizeCanvas(no_image.width, no_image.height, // width, height
        null, ResampleMethod.BICUBICSHARPER);

        var layerRef = app.activeDocument.artLayers.add();
        layerRef.name = "fill";  
        var myColor = new SolidColor();  
        myColor.rgb.red = 255;  
        myColor.rgb.green = 255;  
        myColor.rgb.blue = 255;  
        activeDocument.selection.fill( myColor); 

        var destFileName = no_image.name + ".png";
        doc.exportDocument(new File(destFolder + "/" + destFileName), ExportType.SAVEFORWEB, sfw);
        doc.activeHistoryState = startState; // undo resize
    }

alert("No Images created!");

}

【问题讨论】:

  • 你能不能把当前的活动层和填充层交换?

标签: javascript photoshop jsx photoshop-script


【解决方案1】:

这是您想要做的吗?复制背景层,然后使用填充颜色定位背景?

var docRef = app.activeDocument;

var layerRef = docRef.layers.getByName ("Background").duplicate(); //duplicates the background layer
layerRef.name = "logo"; //renames the duplicated layer.

docRef.activeLayer = docRef.layers.getByName ("Background");//selects the Background layer

var myColor = new SolidColor();  
myColor.rgb.red = 255;  
myColor.rgb.green = 255;  
myColor.rgb.blue = 255;  

activeDocument.selection.fill( myColor); //fills background layer with white.

【讨论】:

    猜你喜欢
    • 2011-01-29
    • 2018-06-16
    • 2015-09-20
    • 2015-09-10
    • 2017-10-05
    • 2013-10-17
    • 1970-01-01
    • 1970-01-01
    • 2018-05-21
    相关资源
    最近更新 更多