Create a 360 Stitch/Reel/Panorama From Active Doc w/Layers

Use this Forum for Beta-Testing your Photoshop Scripts

Moderators: Tom, Kukurykus

IsraelThompson

Create a 360 Stitch/Reel/Panorama From Active Doc w/Layers

Post by IsraelThompson »

I couldn't quickly find what I was looking for by web search, so I wrote a nice little quick and dirty script for use here in our office that seems to do the trick perfectly. Thought I'd share it with anyone who's interested and look forward to recieving any feedback coding suggestions/improvements/critiques offered.

Anyway, here's the skinny on the script:

For use in web-based 360 slideshows, some jQuery plugins (like "jQuery Reel Plugin," as a matter of fact: http://jquery.vostrel.cz/reel) make use of reels, stitches, or panoramic formatted sources. For my particular case, I didn't need to "stitch" in the traditional sense, but needed something more like a tiled reel (loosely coined a "stitched image").

Anyway, the code below is meant to utilize an active PSD document that contains a background layer and any number of layers. It creates a new document based on the active document's dimensions, number of layers present, and default columns specified in the script (which I set to 4). Also, the new document, is set to 72ppi, since this is being used for web.

A resulting image created by the script: http://imageshack.us/photo/my-images/34/360reel.jpg/

It's quick. It's dirty, but it works great for my purpose. Try it out, if you like, and feel free to share critique/feedback on my lazy coding habits:

Code: Select all/*
-------------------------------------------------------------------------------------
Written By; Izz
Date: 7/2011
Description: Creates 360 reel from active document
-------------------------------------------------------------------------------------
 */

// Settings
#target photoshop
app.displayDialogs = DialogModes.NO; // suppress all dialogs
app.bringToFront(); // bring top

var lyrsDocNm = app.activeDocument.name
var lyrsDoc = app.documents.getByName(lyrsDocNm)
var lyrs = lyrsDoc.artLayers.length

var slideWidth = lyrsDoc.width
var slideHeight = lyrsDoc.height
var cols = 4
var rows = Math.ceil(lyrs / cols)

var reelWidth = slideWidth * cols
var reelHeight = slideHeight * rows

var newDoc = app.documents.add(reelWidth, reelHeight, 72, '360 Reel', NewDocumentMode.RGB, DocumentFill.WHITE, 1)

app.activeDocument = lyrsDoc
for (var i = 0; i < lyrsDoc.artLayers.length - 1; i++) {
   lyrsDoc.artLayers.visible = false
}

var lc = 0
for (var i = 0; i < lyrsDoc.artLayers.length - 1; i++) {
   
   lc = lc + 1
   lyrsDoc.artLayers.visible = true
   lyrsDoc.selection.selectAll()
   lyrsDoc.selection.copy(true)
   
   var insideRow = Math.ceil(lc / cols)
   var insideCol = lc - ((insideRow - 1) * cols)
   
   var ulx = slideWidth * (insideCol - 1)
   var uly = slideHeight * (insideRow - 1)
   var llx = ulx
   var lly = uly + slideHeight
   var lrx = llx + slideWidth
   var lry = lly
   var urx = ulx + slideWidth
   var ury = uly
   
   var shapeRef = [[ulx,uly], [llx,lly], [lrx,lry], [urx,ury]]
   app.activeDocument = newDoc
   newDoc.selection.select(shapeRef)
   newDoc.paste()

   app.activeDocument = lyrsDoc
   lyrsDoc.artLayers.visible = false
   
}

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

IsraelThompson

Create a 360 Stitch/Reel/Panorama From Active Doc w/Layers

Post by IsraelThompson »

Wow, that bad, eh?