-
-
Save NimaiMalle/4356e3912b36e1476e13204ca88bd747 to your computer and use it in GitHub Desktop.
#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; |
Hi there,
Im getting an error in Photoshop CS 2020 saying that the make command is not available, line 11.
Any idea how this is caused?
update: I used a layer with points and comma's after renaming to Layer1, Layer2 .... it worked.
Thanks for this very usefull script!
I'm glad you figured it out! I was just testing it out again, after not having used it in a while, and I didn't have any issues. I even tried renaming the layers to use commas and periods in the name, but I still didn't get an error. What was the exact layer name that caused the issue?
Running this script could be one part of a larger workflow, including using Photoshop Actions to record and play back any additional steps.
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.
To use this script, have a Photoshop document open and sized for the Lenticular sheet you'll be using; i.e. 4" x 6" 300 DPI
The document should contain layers for every frame you want to show, and no other layers. No background either. If one of your layers is a "Background" convert it to a Layer.
Run the script.
It will prompt you for the Lines Per Inch (LPI) of the Lenticular sheet; i.e. 40 or 60
The script will add a layer mask to every layer, and the mask will display only one row of pixels from each layer.
Print and watch the magic happen when you put the lens sheet on top!