//”JStablet.jsx” by Ana Tam 2011 for use in Adobe Photoshop //www.anatam.co.uk/projects.html //For re-sizing an image based on in-image scale of known color and size. //copy and paste into text or script editor and save with .jsx extension //Setting ruler units. Tells app to set units as CM if it isn't already set that way. #target photoshop function selectBlue(){ //using eyedropper in Color Range selector var id2382 = charIDToTypeID( "ClrR" ); var desc488 = new ActionDescriptor(); var id2383 = charIDToTypeID( "Fzns" ); desc488.putInteger( id2383, 40 ); var id2384 = charIDToTypeID( "Mnm " ); var desc489 = new ActionDescriptor(); var id2385 = charIDToTypeID( "Lmnc" ); desc489.putDouble( id2385, 13.910000 ); var id2386 = charIDToTypeID( "A " ); desc489.putDouble( id2386, 44.920000 ); var id2387 = charIDToTypeID( "B " ); desc489.putDouble( id2387, -73.620000 ); var id2388 = charIDToTypeID( "LbCl" ); desc488.putObject( id2384, id2388, desc489 ); var id2389 = charIDToTypeID( "Mxm " ); var desc490 = new ActionDescriptor(); var id2390 = charIDToTypeID( "Lmnc" ); desc490.putDouble( id2390, 13.910000 ); var id2391 = charIDToTypeID( "A " ); desc490.putDouble( id2391, 44.920000 ); var id2392 = charIDToTypeID( "B " ); desc490.putDouble( id2392, -73.620000 ); var id2393 = charIDToTypeID( "LbCl" ); desc488.putObject( id2389, id2393, desc490 ); executeAction( id2382, desc488, DialogModes.NO ); } function getSelectionBounds (doc) { //alternative to using bounds function var l = srcDoc.artLayers.add(); srcDoc.selection.fill(app.foregroundColor); var bnds = l.bounds; var hs = srcDoc.historyStates; if (hs[hs.length-2].name == "Layer Order") { srcDoc.activeHistoryState = hs[hs.length-4]; } else { srcDoc.activeHistoryState = hs[hs.length-3]; } for (var i = 0; i < bnds.length; i++) { bnds[i] = bnds[i].value; } return bnds; }; //script work starts var strtRulerUnits = app.preferences.rulerUnits; if (strtRulerUnits != Units.CM) { app.preferences.rulerUnits = Units.CM; } // Pops open a dialog for the user to choose the folder of documents to process var inputFolder = Folder.selectDialog("Select a folder of documents to process"); // Pops open a dialog for the user to set the output folder var outputFolder = Folder.selectDialog("Select a folder for the output files"); // see if we got something interesting from the dialog if (inputFolder != null && outputFolder != null) //function openAllInFolder(){ //Get all the files in the folder \ var fileList = inputFolder.getFiles() // open each file \ for (var i = 0; i < fileList.length; i++) { // The fileList is folders and files so open only files \ if (fileList[i] instanceof File && fileList[i].hidden == false) { //source document var srcDoc = open(fileList[i]) //openAllInFolder() //define target resolution - this is a fixed quantity var n = 300; //resolution in dpi selectBlue() // var BlueSquare = activeDocument.selection.bounds; //for other versions using the function above to get the selection bounds var BlueSquare = getSelectionBounds() var horizBlue = BlueSquare[2] - BlueSquare[0];//lower right corner x - upper left corner x value var vertBlue = BlueSquare [3] - BlueSquare[1];//lower right corner y - upper right corner y value if ((horizBlue / vertBlue) > 1) // it really is around 1.33; then 5cm scale { var c =(0.77/horizBlue);//target size in cm / actual size } else //((horizBlue / vertBlue) < 1) // it really is around 1; then 2cm scale { var c = (0.3 / horizBlue); } //only works if image is rotated correctly, e.g. not on its side //resize image into pixel count defined by "n" - required so that resize using pixels works properly srcDoc.resizeImage(null,null,n,ResampleMethod.BICUBIC); var scale = (c * srcDoc.width*n/2.54);//new size of image in pixels - 2.54 to convert dpi into pixels/cm srcDoc.resizeImage(UnitValue(scale,"px"),null,null,ResampleMethod.BICUBIC); //saveAs(saveIn, options, asCopy, extensionType) TiffSaveOptions = new TiffSaveOptions(); { TiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW } srcDoc.saveAs(outputFolder,TiffSaveOptions,false,Extension.LOWERCASE); srcDoc.close(SaveOptions.DONOTSAVECHANGES) } }