Is it possible in Photoshop to convert slices into photoshop layers

adobe-photoshopgridlayers

What I want to do is to take an image and to cut it up into small squares that are each in a different layer (not export them as individual images). For instance if I had an image that is 100px by 100px and wanted to take that one layer and create 100 layers each 10px by 10px squares. The image would look the same, but instead of being one layer it would be a grid of separate layers that seamlessly fit together like a puzzle. If I turned off the visibility of one of the layers it would look as if one square "piece" of the puzzle was missing.

I know that I can slice up an image in a grid, export the images and then open them as layers using Bridge. The problem with this approach is that I would end up with a 10px by 10px file with 100 layers stacked on top of each other instead of a 100px by 100px file with all of the layers arranged properly.

Thanks.

Best Answer

You can do this all using Javascript. Here's a quick little script I've written, it will copy your image into 100 layers, each 10px by 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();
    }
}

To use it, save that file and load it up with Photoshop by going to

File > Scripts > Browse

Make sure the filetype is set to *.JS

If you want to change the size of your squares just open the JavaSCript file in Notepad, change the value for squareSize and save and run it.

* EDIT *

If you want to do more advanced things with this script, you can download a Photoshop Scripting reference guide which lists all the classes, functions and variables you can work with. (For example how to rotate a layer).

The above script uses JavaScript syntax, however you can also use AppleScript, and VBScript to work with Photoshop.

Related Question