Mobile app version of vmapp.org
Login or Join
Murray664

: Can I automate the creation of random slices within Photoshop? Yeah, let's not worry about the why, but the how. I want to create different sized rectangular slices of an image within Photoshop,

@Murray664

Posted in: #AdobePhotoshop

Yeah, let's not worry about the why, but the how.

I want to create different sized rectangular slices of an image within Photoshop, and print them out. I can do it manually, and it's a long slow process. I'd rather have a tool to automate the initial slicing.

Anyone...? Anyone...?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Murray664

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo857

You can create random slices in Photoshop with scripts.

Here's a .jsx script that creates a random number of slices, anywhere between 50 and 400. The size and position for each slice is random with some restrictions so that the slices stay within the document.

The scrip was made for Photoshop CC 2015, so it's possible that it will not work in anything before Photoshop CS 6.

So, each time you run it, you get a different result:



I hope this helps.

var minimum = 50,
maximum = 400;

function init() {

var ruler_units = preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

var doc = app.activeDocument,
doc_width = doc.width.value,
doc_height = doc.height.value;

for ( var i=0; i < random( minimum, maximum ); i++ ) {

var slice = {
x: random( 0, (doc_width-1) ),
y: random( 0, (doc_height-1) ),
};

slice.width = random( 1, (doc_width - slice.x) ),
slice.height = random( 1, (doc_height - slice.y) );

var top = slice.y,
right = slice.x + slice.width,
bottom = slice.y + slice.height,
left = slice.x;

newSlice( top, right, bottom, left );

}

app.preferences.rulerUnits = ruler_units;

app.beep();
$.sleep(150);
app.beep();

}

function random(min,max) {
return Math.floor(Math.random()*(max-min+1)+min);
}

function newSlice( top, right, bottom, left ) {

// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc9 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref3 = new ActionReference();
var idslice = stringIDToTypeID( "slice" );
ref3.putClass( idslice );
desc9.putReference( idnull, ref3 );
var idUsng = charIDToTypeID( "Usng" );
var desc10 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var idsliceType = stringIDToTypeID( "sliceType" );
var iduser = stringIDToTypeID( "user" );
desc10.putEnumerated( idType, idsliceType, iduser );
var idAt = charIDToTypeID( "At " );
var desc11 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc11.putUnitDouble( idTop, idPxl, top );
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc11.putUnitDouble( idLeft, idPxl, left );
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc11.putUnitDouble( idBtom, idPxl, bottom );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc11.putUnitDouble( idRght, idPxl, right );
var idRctn = charIDToTypeID( "Rctn" );
desc10.putObject( idAt, idRctn, desc11 );
var idslice = stringIDToTypeID( "slice" );
desc9.putObject( idUsng, idslice, desc10 );
executeAction( idMk, desc9, DialogModes.NO );

}

init()

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme