Last active
January 14, 2022 00:03
-
-
Save NimaiMalle/4356e3912b36e1476e13204ca88bd747 to your computer and use it in GitHub Desktop.
Photoshop Script to interleave layers for use with Lenticular Lens Sheets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#target Photoshop | |
function makeLayerMask(maskType) { | |
if( maskType == undefined) maskType = 'RvlS' ; //from selection | |
//requires a selection 'RvlS' complete mask 'RvlA' otherThanSelection 'HdSl' | |
var desc140 = new ActionDescriptor(); | |
desc140.putClass( charIDToTypeID('Nw '), charIDToTypeID('Chnl') ); | |
var ref51 = new ActionReference(); | |
ref51.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Msk ') ); | |
desc140.putReference( charIDToTypeID('At '), ref51 ); | |
desc140.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('UsrM'), charIDToTypeID(maskType) ); | |
executeAction( charIDToTypeID('Mk '), desc140, DialogModes.NO ); | |
} | |
// two element array of numbers for x,y start of line, | |
// two element array of numbers for x,y endof line, | |
//number;line width in pixels | |
// uses foreground color | |
function drawLine( startXY, endXY, width ) { | |
var desc = new ActionDescriptor(); | |
var lineDesc = new ActionDescriptor(); | |
var startDesc = new ActionDescriptor(); | |
startDesc.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), startXY[0] ); | |
startDesc.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), startXY[1] ); | |
lineDesc.putObject( charIDToTypeID('Strt'), charIDToTypeID('Pnt '), startDesc ); | |
var endDesc = new ActionDescriptor(); | |
endDesc.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), endXY[0] ); | |
endDesc.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), endXY[1] ); | |
lineDesc.putObject( charIDToTypeID('End '), charIDToTypeID('Pnt '), endDesc ); | |
lineDesc.putUnitDouble( charIDToTypeID('Wdth'), charIDToTypeID('#Pxl'), width ); | |
desc.putObject( charIDToTypeID('Shp '), charIDToTypeID('Ln '), lineDesc ); | |
if (width != Math.floor(width)) desc.putBoolean( charIDToTypeID('AntA'), true ); | |
executeAction( charIDToTypeID('Draw'), desc, DialogModes.NO ); | |
}; | |
function main() { | |
var doc = app.activeDocument; | |
var numLayers = doc.artLayers.length; | |
var visLayers = 0; | |
for (var i = 0; i < numLayers; i++) doc.artLayers[i].visible && visLayers++; | |
var res = doc.resolution; | |
var lensLPI = Number(prompt("Lenticular Sheet LPI?","40","Lines Per Inch Value")); | |
var lineThickness = res * (1.0/lensLPI) * (1.0/visLayers); | |
if (lineThickness != Math.floor(lineThickness)) { | |
lineThickness = Math.ceil(lineThickness); | |
var idealRes = 1.0 / ((1.0/lineThickness) * (1.0/lensLPI) * (1.0/visLayers)); | |
app.activeDocument.resizeImage(undefined,undefined,idealRes,ResampleMethod.BICUBIC); | |
} | |
preferences.rulerUnits = Units.PIXELS; | |
var j = 0; | |
for (var i = 0; i < numLayers; i++) { | |
var layer = doc.artLayers[i]; | |
if (layer.visible) { | |
app.activeDocument.activeLayer = layer; | |
$.writeln(app.activeDocument.activeLayer.name); | |
var bounds = layer.bounds; | |
activeDocument.selection.selectAll(); | |
makeLayerMask('HdSl'); | |
app.foregroundColor.rgb.red = 255; | |
app.foregroundColor.rgb.green = 255; | |
app.foregroundColor.rgb.blue = 255; | |
for (var y=j*lineThickness; y<bounds[3]; y+= visLayers*lineThickness) { | |
drawLine( [0,y], [bounds[2],y], lineThickness ); | |
// break; | |
} | |
j++; | |
} | |
// break; | |
} | |
} | |
var originalRulerUnits = preferences.rulerUnits; | |
preferences.rulerUnits = Units.INCHES; | |
main(); | |
preferences.rulerUnits = originalRulerUnits; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Love it. Beautiful. Thank you so much!
Just getting into Lenticular photography, looking forward to testing this out with some photos and some plastic sheets I just ordered.