Skip to main content
Known Participant
February 22, 2025
Answered

How to create a brick-shaped layer that fills the entire canvas

  • February 22, 2025
  • 4 replies
  • 863 views

I want to draw layered rectangular shape layers in the image, similar to a brick effect, but I don't know how to accomplish this. The image below was manually pieced together. I hope to control the number of brick columns using variables Thank you all for your help

Correct answer c.pfaffenbichler

If you should need to actually split the image into »brick«-Layers one could use a Script to create a Path and use the individual subPathItems to copy content to a new Layer. 

 

Edit: Instead of creating a Path one could naturally just create Selections straight away and use those for »Layer Via Copy«.

 

 

 

// create rectangular subPathItems in a brick-like pattern;
// 2025, use it at your own risk;
if (app.documents.length > 0) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var myDocument = activeDocument;
// the values;
var lines = 10;
var rows = 5; 
var seam = 10;
// the dimensions;
var seam = seam * (72/myDocument.resolution);
var width1 = (myDocument.width * (72/myDocument.resolution) - seam * (rows - 1)) / rows;
var height1 = (myDocument.height * (72/myDocument.resolution) - seam * (lines - 1)) / lines;
// create path;
var anArray = [];
for (var x = 0; x < lines; x++) {
var theX = 0;
var theY = height1 * x + seam * x;
var bricksPerLine = rows;
if (String(x/2).indexOf(".") != -1) {
var theX = (-0.5) * (width1 + seam);
var bricksPerLine = rows+1;
};
for (var y = 0; y < bricksPerLine; y++) {
thisArray = new Array;
thisArray.push([[theX, theY], [theX, theY], [theX, theY], false]);
thisArray.push([[theX+width1, theY], [theX+width1, theY], [theX+width1, theY], false]);
thisArray.push([[theX+width1, theY+height1], [theX+width1, theY+height1], [theX+width1, theY+height1], false]);
thisArray.push([[theX, theY+height1], [theX, theY+height1], [theX, theY+height1], false]);
thisArray.push(true);
thisArray.push(1737);
anArray.push(thisArray)
var theX = theX + width1 + seam;
}
};
// create path;
createPath2022(anArray, Math.random());
// reset;
app.preferences.rulerUnits = originalRulerUnits;
};
////////////////////////////////////
////// create a path from collectPathInfoFromDesc2012-array //////
function createPath2022(theArray, thePathsName) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// thanks to xbytor;
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty(cTID('Path'), cTID('WrPt'));
    desc1.putReference(sTID('null'), ref1);
    var list1 = new ActionList();
	
for (var m = 0; m < theArray.length; m++) {
	var thisSubPath = theArray[m];
	
    var desc2 = new ActionDescriptor();
    desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);
    var list2 = new ActionList();
    var desc3 = new ActionDescriptor();
    desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);
    var list3 = new ActionList();
	
for (var n = 0; n < thisSubPath.length - 2; n++) {
	var thisPoint = thisSubPath[n];
	
    var desc4 = new ActionDescriptor();
    var desc5 = new ActionDescriptor();
    desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);
    desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);
    desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);
    var desc6 = new ActionDescriptor();
    desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);
    desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);
    desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);
    var desc7 = new ActionDescriptor();
    desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);
    desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);
    desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);
    desc4.putBoolean(cTID('Smoo'), thisPoint[3]);
    list3.putObject(cTID('Pthp'), desc4);
	
	};
	
    desc3.putList(cTID('Pts '), list3);
    list2.putObject(cTID('Sbpl'), desc3);
    desc2.putList(cTID('SbpL'), list2);
    list1.putObject(cTID('PaCm'), desc2);
	};
	
    desc1.putList(cTID('T   '), list1);
    executeAction(cTID('setd'), desc1, DialogModes.NO);

// name work path;
var desc30 = new ActionDescriptor();
var ref6 = new ActionReference();
var idPath = charIDToTypeID( "Path" );
ref6.putClass( idPath );
desc30.putReference( charIDToTypeID( "null" ), ref6 );
var ref7 = new ActionReference();
ref7.putProperty( idPath, charIDToTypeID( "WrPt" ) );
desc30.putReference( charIDToTypeID( "From" ), ref7 );
desc30.putString( charIDToTypeID( "Nm  " ), thePathsName );
executeAction( charIDToTypeID( "Mk  " ), desc30, DialogModes.NO );
/// get index;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("itemIndex"));
ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var pathDesc = executeActionGet(ref);
app.preferences.rulerUnits = originalRulerUnits;
return pathDesc.getInteger(stringIDToTypeID("itemIndex"))
};

 

edited 2025-03-09

4 replies

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
March 8, 2025

If you should need to actually split the image into »brick«-Layers one could use a Script to create a Path and use the individual subPathItems to copy content to a new Layer. 

 

Edit: Instead of creating a Path one could naturally just create Selections straight away and use those for »Layer Via Copy«.

 

 

 

// create rectangular subPathItems in a brick-like pattern;
// 2025, use it at your own risk;
if (app.documents.length > 0) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var myDocument = activeDocument;
// the values;
var lines = 10;
var rows = 5; 
var seam = 10;
// the dimensions;
var seam = seam * (72/myDocument.resolution);
var width1 = (myDocument.width * (72/myDocument.resolution) - seam * (rows - 1)) / rows;
var height1 = (myDocument.height * (72/myDocument.resolution) - seam * (lines - 1)) / lines;
// create path;
var anArray = [];
for (var x = 0; x < lines; x++) {
var theX = 0;
var theY = height1 * x + seam * x;
var bricksPerLine = rows;
if (String(x/2).indexOf(".") != -1) {
var theX = (-0.5) * (width1 + seam);
var bricksPerLine = rows+1;
};
for (var y = 0; y < bricksPerLine; y++) {
thisArray = new Array;
thisArray.push([[theX, theY], [theX, theY], [theX, theY], false]);
thisArray.push([[theX+width1, theY], [theX+width1, theY], [theX+width1, theY], false]);
thisArray.push([[theX+width1, theY+height1], [theX+width1, theY+height1], [theX+width1, theY+height1], false]);
thisArray.push([[theX, theY+height1], [theX, theY+height1], [theX, theY+height1], false]);
thisArray.push(true);
thisArray.push(1737);
anArray.push(thisArray)
var theX = theX + width1 + seam;
}
};
// create path;
createPath2022(anArray, Math.random());
// reset;
app.preferences.rulerUnits = originalRulerUnits;
};
////////////////////////////////////
////// create a path from collectPathInfoFromDesc2012-array //////
function createPath2022(theArray, thePathsName) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// thanks to xbytor;
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty(cTID('Path'), cTID('WrPt'));
    desc1.putReference(sTID('null'), ref1);
    var list1 = new ActionList();
	
for (var m = 0; m < theArray.length; m++) {
	var thisSubPath = theArray[m];
	
    var desc2 = new ActionDescriptor();
    desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);
    var list2 = new ActionList();
    var desc3 = new ActionDescriptor();
    desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);
    var list3 = new ActionList();
	
for (var n = 0; n < thisSubPath.length - 2; n++) {
	var thisPoint = thisSubPath[n];
	
    var desc4 = new ActionDescriptor();
    var desc5 = new ActionDescriptor();
    desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);
    desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);
    desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);
    var desc6 = new ActionDescriptor();
    desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);
    desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);
    desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);
    var desc7 = new ActionDescriptor();
    desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);
    desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);
    desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);
    desc4.putBoolean(cTID('Smoo'), thisPoint[3]);
    list3.putObject(cTID('Pthp'), desc4);
	
	};
	
    desc3.putList(cTID('Pts '), list3);
    list2.putObject(cTID('Sbpl'), desc3);
    desc2.putList(cTID('SbpL'), list2);
    list1.putObject(cTID('PaCm'), desc2);
	};
	
    desc1.putList(cTID('T   '), list1);
    executeAction(cTID('setd'), desc1, DialogModes.NO);

// name work path;
var desc30 = new ActionDescriptor();
var ref6 = new ActionReference();
var idPath = charIDToTypeID( "Path" );
ref6.putClass( idPath );
desc30.putReference( charIDToTypeID( "null" ), ref6 );
var ref7 = new ActionReference();
ref7.putProperty( idPath, charIDToTypeID( "WrPt" ) );
desc30.putReference( charIDToTypeID( "From" ), ref7 );
desc30.putString( charIDToTypeID( "Nm  " ), thePathsName );
executeAction( charIDToTypeID( "Mk  " ), desc30, DialogModes.NO );
/// get index;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("itemIndex"));
ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var pathDesc = executeActionGet(ref);
app.preferences.rulerUnits = originalRulerUnits;
return pathDesc.getInteger(stringIDToTypeID("itemIndex"))
};

 

edited 2025-03-09

Known Participant
March 9, 2025

Thank you very much, thanks

Bojan Živković11378569
Community Expert
Community Expert
February 23, 2025

Do you mean the Variables from the Image menu or a variable number of bricks? If you want a way to manually enter the number of bricks and hit the play button, then you need a script. It can be done using actions, but it's a tedious job, and you need to know how many in advance because there are a gazillion possible combinations. For each combination, one must record a separate action.

Trevor.Dennis
Community Expert
Community Expert
February 23, 2025

Are you looking for help with scripting specifically?

How should the brick texture interact with the background image?I am sure you'll know how to find and use texture layers via stock sites.

I expect you'll also know the trick of setting Fill Opacity to 0% which shows the layer style without the layer's content?

Known Participant
February 23, 2025

Thank you for your reply. I understand that it can be done using patterns, but my requirement is not just to draw rectangles. Later, I will convert the drawn rectangles into selections, then copy each piece of the image and export them to a folder.

Trevor.Dennis
Community Expert
Community Expert
February 23, 2025

Now that does sound like something you'd need to automate if possible.

Known Participant
February 23, 2025

Thank you for your reply

c.pfaffenbichler
Community Expert
Community Expert
February 23, 2025

Could you provide a meaningful example – a source image and (a portion of) the images you want to achieve/output ultimately?