2

Resolved: Thanks for the help, everyone! The script by Sergey Kritskiy works to export storyboards with sequential file-name.


I just found a script by TunaMaxx the other day and thought it was super helpful to export my storyboards.

Right now it exports the entire first column, then 2nd column then 3rd and 4th column. I end up with my boards labeled in the wrong order of "1, 5, 9, 13" then "2, 6, 10, 14" and so on. (images below)

I was wondering if it's possible to somehow have it export it by rows, so my boards are saved/titled as "1, 2, 3 ,4..,etc?" It seems like not a big deal, but when I'm exporting 200+ boards, it's a hassle to go back and re-organize all of this. (Without the script, I resort to creating guide lines and using slice tool.)

I included screenshots below of what I'm looking for in photoshop and what it looks like after the export.

Below is the JPEG I'm working with. Each frame is 2000px wide by 1090px tall. The x offset is 200px and the y offset is 100px. Original File to Export

The photo below shows what happen when I try to export enter image description here

incorrect export

  • did u edited my script as per your custom values??? – Mr.Online Apr 24 at 10:58
  • Yes, I adjust the width and height to 2000px x 1090px and xoffset is 200px, yoffset is 100px. Not sure why it exports with gutter – Para Di Apr 24 at 11:02
2

Try this:

// Alter these as needed
var cellWidth         = 2000; // The width, in px, of your image cell
var cellHeight        = 1090; // The height, in px, of your image cell
var xOffset           = 200; // The space, in px, between each cell in a row
var yOffset           = 100; // The space, in px, between each row. Set to 0 for traditional checker board effect
var options           = new ExportOptionsSaveForWeb();
options.format    = SaveDocumentType.JPEG;
options.quality   = 100;

// Don't change these unless you know why you should! :)
var doc               = app.activeDocument;
var dname             = doc.name.substr(0,doc.name.length-4);
var dir               = doc.path.toString()+"/";
var rowShift          = true;
var imageWidth        = activeDocument.width.as('px');
var imageHeight       = activeDocument.height.as('px');

// Store the current rulerUnits for later. We're going to change
// it to pixels for now, and we want to change it back later.
var myRulerUnits = app.preferences.rulerUnits;

// Set rulerUnits to pixels
app.preferences.rulerUnits = Units.PIXELS;

// Find the "Background"
var layerRef = doc.artLayers.getByName("Background");

// Set our "Background" to be a Layer
layerRef.isBackgroundLayer = false;

// Reduce the Canvas size to our cell size
doc.resizeCanvas(cellWidth, cellHeight, AnchorPosition.TOPLEFT);

var totalOffset = 0;
var xMovement = 0;
var yMovement = 0;

// Do the magic
for (var y = 0; y < numberOfRows(); y++)
{
    totalOffset = 0;

    for (var x = 0; x < numberOfCells(); x++)
    {
        if (x == 0)
        {
            xMovement = 0;
            totalOffset += xMovement;
            yMovement = yOffset
        }
        else
        {
            xMovement = cellWidth;
            totalOffset += (xMovement+xOffset);
            yMovement = 0
        }           

        // Offset the layer into our Canvas "window"
        layerRef.applyOffset(-(xMovement+xOffset), -yMovement, OffsetUndefinedAreas.WRAPAROUND);

        saveCell(y,x);
    };

    // Offset the layer back to the left and down one row
    layerRef.applyOffset(totalOffset+xOffset, -(cellHeight), OffsetUndefinedAreas.WRAPAROUND);

    // Flip the rowShift. If it was true, make it false and vice versa.
    rowShift = !rowShift;
};

// Calculate number of cells per row. May change depending in rowShift, etc
function numberOfCells()
{
    var theWidth = imageWidth;

    if (rowShift == true)
    {
        var theWidth = theWidth - xOffset; 
    }
    return Math.floor((theWidth + xOffset) / (cellWidth + xOffset));
}

// Calculate number of rows
function numberOfRows()
{
    return Math.floor((imageHeight + yOffset) / (cellHeight + yOffset));
}

// Pad the cell x and y numbers for proper sorting
function pad(num, size)
{
    var s = "000000000" + num;
    return s.substr(s.length-size);
}

// Actually save, or really "Save For Web" the cell
function saveCell(x, y)
{
    var nname = dname + "_" + pad((x + 1), 3) + "_" + pad((y + 1), 3);

    doc.exportDocument (new File(dir + "/" + nname + ".jpg"), ExportType.SAVEFORWEB, options);
}

// Reset the ruler units
app.preferences.rulerUnits = myRulerUnits;

P.S. do you need the frames to have row/column or you want them to have sequential names?

  • Oh my goodnessThank you so much! Your script works. It all exported within the frame and has the correct sequential file-name too. Thanks, Sergey! – Para Di Apr 24 at 23:00
1

Does This Works?? :)

    // Alter these as needed
var cellWidth         = 240; // The width, in px, of your image cell
var cellHeight        = 240; // The height, in px, of your image cell
var xOffset           = 240; // The space, in px, between each cell in a row
var yOffset           = 240; // The space, in px, between each row. Set to 0 for traditional checker board effect
var options           = new ExportOptionsSaveForWeb();
    options.format    = SaveDocumentType.JPEG;
    options.quality   = 75;

// Don't change these unless you know why you should! :)
var doc               = app.activeDocument;
var dname             = doc.name.substr(0,doc.name.length-4);
var dir               = doc.path.toString()+"/";
var rowShift          = true;
var imageWidth        = activeDocument.width.as('px');
var imageHeight       = activeDocument.height.as('px');

// Store the current rulerUnits for later. We're going to change
// it to pixels for now, and we want to change it back later.
var myRulerUnits = app.preferences.rulerUnits;

// Set rulerUnits to pixels
app.preferences.rulerUnits = Units.PIXELS;

// Find the "Background"
var layerRef = doc.artLayers.getByName("Background");

// Set our "Background" to be a Layer
layerRef.isBackgroundLayer = false;

// Reduce the Canvas size to our cell size
doc.resizeCanvas(cellWidth, cellHeight, AnchorPosition.TOPLEFT);

var totalOffset = 0;
var xMovement = 0;

// Do the magic
for (var y = 0; y < numberOfRows(); y++)
{
    totalOffset = 0;

    for (var x = 0; x < numberOfCells(); x++)
    {
        if (x == 0)
        {
            xMovement = (rowShift) ? xOffset : 0;
        }
        else
        {
            xMovement = cellWidth + xOffset;
        }

        totalOffset += xMovement;

        // Offset the layer into our Canvas "window"
        layerRef.applyOffset(-(xMovement), 0, OffsetUndefinedAreas.WRAPAROUND);

        saveCell(x,y);
    };

    // Offset the layer back to the left and down one row
    layerRef.applyOffset(totalOffset, -(cellHeight + yOffset), OffsetUndefinedAreas.WRAPAROUND);

    // Flip the rowShift. If it was true, make it false and vice versa.
    rowShift = !rowShift;
};

// Calculate number of cells per row. May change depending in rowShift, etc
function numberOfCells()
{
    var theWidth = imageWidth;

    if (rowShift == true)
    {
        var theWidth = theWidth - xOffset; 
    }
    return Math.floor((theWidth + xOffset) / (cellWidth + xOffset));
}

// Calculate number of rows
function numberOfRows()
{
    return Math.floor((imageHeight + yOffset) / (cellHeight + yOffset));
}

// Pad the cell x and y numbers for proper sorting
function pad(num, size)
{
    var s = "000000000" + num;
    return s.substr(s.length-size);
}

// Actually save, or really "Save For Web" the cell
function saveCell(x, y)
{
    var nname = dname + "_" + pad((y + 1), 3) + "_" + pad((x + 1), 3);

    doc.exportDocument (new File(dir + "/" + nname + ".jpg"), ExportType.SAVEFORWEB, options);
}

// Reset the ruler units
app.preferences.rulerUnits = myRulerUnits;
  • 1
    1 minute faster :) (+1). – George Profenza Apr 24 at 10:41
  • Thank you for the help! I've encountered one new problem with offsets now – Para Di Apr 24 at 10:55
  • well ; even original have issues too :P think i gonna understand it completely XD – Mr.Online Apr 24 at 11:42
1

In TunaMaxx's code you will notice this function:

// Actually save, or really "Save For Web" the cell
function saveCell(x, y)
{
    var nname = dname + "_" + pad((x + 1), 3) + "_" + pad((y + 1), 3);

    doc.exportDocument (new File(dir + "/" + nname + ".jpg"), ExportType.SAVEFORWEB, options);
}

It is called earlier in code:

saveCell(x,y);

It looks like what you're after is simply swapping x and y to have the increments horizontally.

try changing saveCell(x,y); with saveCell(y,x);

The only other thing to keep in mind is adjusting these as needed:

var xOffset           = 240; // The space, in px, between each cell in a row
var yOffset           = 240; // The space, in px, between each row. Set to 0 for traditional checker board effect

(I remember I needed a diagonally offset grid originally)

  • i just swapped x,y positions in my answer and it working for me3 – Mr.Online Apr 24 at 10:45
  • Thank you so much! Now I have a new problem with the offsets. I've updated this question to include one more photo. Am I entering the offset incorrectly? – Para Di Apr 24 at 10:55
  • what happens if you set the x and y offsets to 0 ? – George Profenza Apr 24 at 11:00
  • When it's both set to 0, the exports are completely off the frame and shows gutter in all the 16 images. yikes – Para Di Apr 24 at 11:05
  • Oooops :) Do cellWidth and cellHeight match your single image dimensions within the larger composition ? What does your original document looks like ? – George Profenza Apr 24 at 11:08

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.