I’m trying to create a pattern script in Photoshop that duplicates an image horizontally and vertically over the whole canvas. But the issue is that across the x-axis it doubles its value every loop. If I remove the “j” loop, it works fine.
This pic will show you the issue I’m referring to https://imgur.com/a/0x9HhCS
var offset = parseInt(prompt("Type in the offset (spacing between pics) value here.nDefault is 0px.", "0"));
for (var i = 0; i < width / (layerWidth + offset); i++) {
for (var j = 0; j < 3; j++) {
app.activeDocument.layers[i, j].duplicate()
app.activeDocument.layers[i, j].translate(i * (layerWidth + offset), j * (layerHeight + offset));
}
}
2
Answers
the issue is related in how do you use
offset
:Translate refers to the bounding rect of the layer.
If you have a 50px width image translated by 50px, the resulting layer width will be 100px.
Try to use only the
offset
, each iteration.As volcanic mentioned,
layers[i, j]
isn’t a valid way of accessing your layers. I’m not even sure why this works. You’re supposed to select you original layer, make a copy and translate it. Something like this:Result: