Copy link to clipboard
Copied
Sorry if this is basic, is there a way to script the selection of a random area in photoshop?
Sorry if this is basic, is there a way to script the selection of a random area in photoshop?
By @Mark5C6C
I wouldn't say it's basic, but it's possible.
I presume that you are referring to both the size and position. I would expect that there should be both a minimum and maximum size for the selection compared to the canvas size. What other criteria, such as the canvas edges, is it OK for the selection to go to the edge of the canvas, or should it always have a "safe zone" where it has to
...Copy link to clipboard
Copied
you can use a selection tool for example the square and generate an image inside that box.
Copy link to clipboard
Copied
Truly random? As in whatever area the script decides randomly?
Copy link to clipboard
Copied
Sorry if this is basic, is there a way to script the selection of a random area in photoshop?
By @Mark5C6C
I wouldn't say it's basic, but it's possible.
I presume that you are referring to both the size and position. I would expect that there should be both a minimum and maximum size for the selection compared to the canvas size. What other criteria, such as the canvas edges, is it OK for the selection to go to the edge of the canvas, or should it always have a "safe zone" where it has to keep away from the canvas edges? Is this a rectangular selection or something else?
What is the use case?
Edit: This is what ChatGPT regurgitated:
// Ensure a document is open
if (app.documents.length > 0) {
var doc = app.activeDocument;
// Get the canvas dimensions
var canvasWidth = doc.width.as("px");
var canvasHeight = doc.height.as("px");
// Generate random values for the selection
var randomWidth = Math.floor(Math.random() * canvasWidth);
var randomHeight = Math.floor(Math.random() * canvasHeight);
var randomX = Math.floor(Math.random() * (canvasWidth - randomWidth));
var randomY = Math.floor(Math.random() * (canvasHeight - randomHeight));
// Define the selection coordinates
var selectionCoords = [
[randomX, randomY],
[randomX + randomWidth, randomY],
[randomX + randomWidth, randomY + randomHeight],
[randomX, randomY + randomHeight]
];
// Make the selection
doc.selection.select(selectionCoords);
// Inform the user
alert("Random selection created at (" + randomX + ", " + randomY + ") with dimensions " + randomWidth + "x" + randomHeight + " pixels.");
} else {
alert("No document is open. Please open a document and try again.");
}