是否可以在 Photoshop 中将切片转换为 Photoshop 图层?

MJR*_*MJR 5 grid adobe-photoshop layers

我想要做的是拍摄一张图像并将其切成小方块,每个小方块都在不同的图层中(而不是将它们导出为单独的图像)。例如,如果我有一个 100 像素 x 100 像素的图像,并且想要获取该图层并创建 100 个图层,每个图层为 10 像素 x 10 像素的正方形。图像看起来是一样的,但它不是一个层,而是一个由独立层组成的网格,它们像拼图一样无缝地组合在一起。如果我关闭其中一层的可见性,它看起来好像缺少一块方形的拼图。

我知道我可以在网格中切出图像,导出图像,然后使用 Bridge 将它们作为图层打开。这种方法的问题在于,我最终会得到一个 10px x 10px 的文件,其中 100 个层相互堆叠,而不是一个 100px x 100px 的文件,所有层都正确排列。

谢谢。

小智 7

您可以使用 Javascript 完成这一切。这是我写的一个快速小脚本,它会将您的图像复制到 100 个图层中,每个图层为 10px x 10px:

/*
--------Photoshop Script - Grid to Layers------------
Author: Oisin Conolly
        www.DigitalBiscuits.co.uk

This basic script will create new layers from your active layer, each equal in size according to the grid dimensions specified.
*/


//this is the size of our squares in pixels
var squareSize = 10;



var docRef = app.activeDocument;

//set the ruler type
if (app.preferences.rulerUnits != Units.PIXELS)
{
    app.preferences.rulerUnits = Units.PIXELS;
}

var layerRef = docRef.activeLayer;

for (y = 0; y<docRef.height; y+=squareSize)
{
    for (x = 0; x<docRef.width; x+=squareSize)
    {
        //activate the original layer
        docRef.activeLayer = layerRef;
        //make the selection
        docRef.selection.select(Array (Array(x, y), Array(x, y+squareSize), Array(x+squareSize,y+squareSize), Array(x+squareSize,y)), SelectionType.REPLACE, 0, false);
    
        //copy the selection
        docRef.selection.copy();
        //create and paste new layer
        docRef.artLayers.add();
        docRef.paste();
    }
}
Run Code Online (Sandbox Code Playgroud)

要使用它,请保存该文件并通过转到 Photoshop 将其加载

文件 > 脚本 > 浏览

确保文件类型设置为 *.JS

如果您想更改方块的大小,只需在记事本中打开 JavaSCRipt 文件,更改其值squareSize并保存并运行它。

* 编辑 *

如果您想使用此脚本执行更高级的操作,您可以下载Photoshop 脚本参考指南,其中列出了您可以使用的所有类、函数和变量。(例如如何旋转图层)。

上述脚本使用 JavaScript 语法,但您也可以使用 AppleScript 和 VBScript 来处理 Photoshop。