How to create a brick-shaped layer that fills the entire canvas
Copy link to clipboard
Copied
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
Explore related tutorials & articles
Copy link to clipboard
Copied
The following code was written using GPT. I'm not sure why a part of the rectangles is missing?
#target photoshop
// Get the current document
var doc = app.activeDocument;
// Basic parameters
var rows = 15; // Number of rows for the brick wall
var cols = 3; // Number of columns for the brick wall
// Get canvas dimensions
var canvasWidth = doc.width;
var canvasHeight = doc.height;
// Calculate the width and height of each brick
var brickWidth = canvasWidth / cols;
var brickHeight = canvasHeight / rows;
// Create the brick wall
for (var row = 0; row < rows; row++) {
for (var col = 0; col < cols; col++) {
// Staggered layout, shift odd rows by half a brick's width
var xPos = col * brickWidth;
if (row % 2 == 1) {
xPos += brickWidth / 2; // Stagger odd rows
}
var yPos = row * brickHeight; // Keep vertical position consistent
createBrick(xPos, yPos, brickWidth, brickHeight);
}
}
function createBrick(x, y, width, height) {
// Create rectangle
var layer = doc.artLayers.add();
layer.name = "Brick_" + x + "_" + y;
doc.selection.select([
[x, y],
[x + width, y],
[x + width, y + height],
[x, y + height]
]);
// Fill with color
var color = new SolidColor();
color.rgb.hexValue = "FF6B6B"; // Set brick color
doc.selection.fill(color);
doc.selection.deselect();
}
Copy link to clipboard
Copied
Could you provide a meaningful example – a source image and (a portion of) the images you want to achieve/output ultimately?
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Now that does sound like something you'd need to automate if possible.
Copy link to clipboard
Copied
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.

