Skip to main content
ncxaesthetic
Participant
July 28, 2019
Question

HELP- Complex question about layers regarding pixel art:

  • July 28, 2019
  • 3 replies
  • 474 views

Say you have a checkerboard that is 32 blocks wide by 8 blocks tall where each individual block is 8 pixels by 8 pixels.

The image on the checkerboard doesn't take up all 896 blocks, so more than 50% of the layer is transparent.

My goal is to capture each individual block onto it's own layer; however, doing that manually would take absolutely forever.

Is there a way to run a series of settings that allows Photoshop to automatically separate the whole layer into individual 8x8 layers so that each layer is an accurately cut piece of the checkerboard image?

I'm using Photoshop CS6 by the way.​

This topic has been closed for replies.

3 replies

rayek.elfin
Legend
July 28, 2019

Just out of curiosity: why the need to separate blocks this way? Do you require this to create a level?

JJMack
Community Expert
Community Expert
July 28, 2019

An automated process can be scripted to do what you want.  The script would try to create 896 layers a matrix 28 rows 32 columns of 8x8 tiles from your document content by making 8x8 selection  duping the selection as a layer when pixels are selected.  When  a selection fail to select pixels the script moves on to the next selection. After the 896 selection attempts there should be some number of layers above the documents original layer which would then be deleted. What would be left would be some layers with a 8x8px tile positioned over the documents 256px by 224px canvas size where the content should be located. The script would take some time to run you could enjoy a glass of wine while it runs. 

JJMack
c.pfaffenbichler
Community Expert
Community Expert
July 28, 2019

I have an old Script that uses the guides to split a Layer, so I asked about the Guide Layouts.

c.pfaffenbichler
Community Expert
Community Expert
July 28, 2019

Did CS6 already have

View > New Guide Layout

?

ncxaesthetic
Participant
July 28, 2019

Not that I'm seeing, no. CS6 only allows you to make a new guide and set it manually, however it doesn't appear as though there's a way to give it a layout.

c.pfaffenbichler
Community Expert
Community Expert
July 29, 2019

You can try this:

// split layer;

// 2019, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var myResolution = myDocument.resolution;

myDocument.resizeImage(undefined, undefined, 72, ResampleMethod.NONE);

var theLayer = myDocument.activeLayer;

var layerID = getLayerId(theLayer);

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

var docWidth = myDocument.width;

var docHeight = myDocument.height;

// the dimensions;

var theWidth = 8;

var theHeight = 8;

// create array;;

var theVer = new Array;

var theHor = new Array;

for (var m = 0; m < Math.ceil (docWidth/theWidth) + 1; m++) {

  theVer.push(theWidth*m)

  };

for (var n = 0; n < Math.ceil (docHeight/theHeight) + 1; n++) {

  theHor.push(theHeight*n)

  };

// create selections;

var theCount = 1;

for (var y = 0; y < theHor.length - 1; y++) {

  var Y1 = theHor;

  var Y2 = theHor[y+1];

  for (var x = 0; x < theVer.length - 1; x++) {

  try {

  var X1 = theVer;

  var X2 = theVer[x+1];

$.writeln(Y1+"_"+X1+"_"+Y2+"_"+X2+"___"+theCount++)

  rectangularSelection([Y1, X1, Y2, X2], false);

// layer via copy;

  var id14 = charIDToTypeID( "CpTL" );

  executeAction( id14, undefined, DialogModes.NO );

  } catch (e) {};

// reselct layer;

  myDocument.activeLayer = theLayer;

  };

  };

// reset the ruler units;

myDocument.resizeImage(undefined, undefined, myResolution, ResampleMethod.NONE);

app.preferences.rulerUnits = originalRulerUnits

};

////////////////// the functions //////////////////

////// rectangular selection //////

function rectangularSelection (theBounds, add) {

// =======================================================

if (add == false ||  add == undefined) {var idsetd = charIDToTypeID( "setd" )}

else {var idsetd = charIDToTypeID( "AddT" )};

    var desc55 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref11 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref11.putProperty( idChnl, idfsel );

    desc55.putReference( idnull, ref11 );

    var idT = charIDToTypeID( "T   " );

        var desc56 = new ActionDescriptor();

        var idTop = charIDToTypeID( "Top " );

        var idRlt = charIDToTypeID( "#Rlt" );

        desc56.putUnitDouble( idTop, idRlt, theBounds[0] );

        var idLeft = charIDToTypeID( "Left" );

        var idRlt = charIDToTypeID( "#Rlt" );

        desc56.putUnitDouble( idLeft, idRlt, theBounds[1] );

        var idBtom = charIDToTypeID( "Btom" );

        var idRlt = charIDToTypeID( "#Rlt" );

        desc56.putUnitDouble( idBtom, idRlt, theBounds[2] );

        var idRght = charIDToTypeID( "Rght" );

        var idRlt = charIDToTypeID( "#Rlt" );

        desc56.putUnitDouble( idRght, idRlt, theBounds[3] );

    var idRctn = charIDToTypeID( "Rctn" );

    desc55.putObject( idT, idRctn, desc56 );

executeAction( idsetd, desc55, DialogModes.NO );

};

// by mike hale, via paul riggott;

function getLayerId(theLayer){

// http://forums.adobe.com/message/1944754#1944754

app.activeDocument.activeLayer = theLayer;

//Assumes activeDocument and activeLayer

    var ref = new ActionReference();

    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

    d = executeActionGet(ref);

return d.getInteger(charIDToTypeID('LyrI'));

};