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; |
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?
Hi Nimai,
Thanks for the response, I was thinking that the issue might be related to
a very long name as well, I name my photos after the geolocation
coordinates schicht usually consists of numbers points and commas totaling
more than 20 characters, I’ll test a little bit more tonight to try finding
what’s causing the issue.
I was also thinking that this app could be more eleborate. The power of
this script I think is that it is made for photoshop which already houses
all pre and post editing capacity and that it works cross platform in
contrast to most lenticular apps that are made for windows.
I was thinkering on it and imagined that it could house more functionality
like using the whole images, horizontal scale them -50% cut them up in
slices and combine these two sets in one image. That’s how I’ve read most
apps create one image like for example 3D mix projector.
Secondly the possibility to make a calibration sheet would make this
professionally usable.
I know some scripting but not well enough yet. Maybe interesting for
development.
Best,
Crispijn van Sas
Op di 23 mrt. 2021 om 14:07 schreef Nimai Malle ***@***.***>
***@***.**** commented on this gist.
------------------------------
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?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/4356e3912b36e1476e13204ca88bd747#gistcomment-3676520>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABQIEL4ACBAWKJC4L7LI7ADTFCG7RANCNFSM4ZRSL7HQ>
.
--
best,
Crispijn van Sas
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
image with the error