0

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...?

  • Hi Andrew, welcome to GDSE and thanks for your question. If you want to know more about the site, please see the help center or ping one of us in the Graphic Design Chat once your reputation is sufficient (20). Keep contributing and enjoy the site! – Vincent Oct 15 '15 at 11:43
  • @Joonas - no, this is really the problem I'm trying to solve. Thanks for playing. – Andrew McDonald Oct 16 '15 at 15:58
  • I'm sure it is the problem you are trying to solve, but whether or not this is the best way to approach it, I'm not too sure. Just generally, everything you've written so far has this passive aggressive tone that is more than unnecessary. If you'd give the "why", it would make the question clearer and easier to answer and you straight up declared that you ain't giving that up. If I forget all that, I'd still need more details to answer the question. What defines the size, position and number of slices? – Joonas Oct 16 '15 at 19:48
  • Now this ties to the "why". Maybe you have multiple identically sized documents with 3 images side by side, which you are trying to slice to make them individual pictures. This would immediately tell me that the size, number and position of the slices is always the same. Since I don't know, I can only guess and there is only so much time... To be fair, you did say "random slices" but you didn't say which part(s) of it are random. With this, I give you my answer below. – Joonas Oct 16 '15 at 19:48
1

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:

enter image description here

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()
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.