Copy link to clipboard
Copied
Hi All,
I need some help finding a script that I'm sure must be out there (or easy to create for those who actually know hot to write scripts..)
I'm trying to batch crop multiple photos (PSDs) from a path that is already in the files (named "Crop (Capture One)".
With actions I can only go so far, because:
-When converting path to selection and using crop tool, the crop tool records specific XY coordinates, not the path coordinates.
-Using Image/Crop makes the right crop but deletes the pixels outside the crop area.
I would like to find a way to directly crop according to the path, without deleting the pixels outside the crop zone...
Any Ideas out there?
Thanks a million,
J
Try here:
Here is the full code:
/*
Crop to Named Path Retaining Pixels.jsx
v1.1, Stephen Marsh, 13th September 2021
https://community.adobe.com/t5/photoshop-ecosystem-discussions/need-script-to-crop-to-path-without-deleting-pixels/td-p/12378330
Need script to crop to path without deleting pixels
*/
if (app.documents.length) {
var doc = app.activeDocument;
var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Unit
...
Copy link to clipboard
Copied
Try here:
Here is the full code:
/*
Crop to Named Path Retaining Pixels.jsx
v1.1, Stephen Marsh, 13th September 2021
https://community.adobe.com/t5/photoshop-ecosystem-discussions/need-script-to-crop-to-path-without-deleting-pixels/td-p/12378330
Need script to crop to path without deleting pixels
*/
if (app.documents.length) {
var doc = app.activeDocument;
var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
try {
doc.pathItems.getByName("Crop (Capture One)");
} catch (e) {
alert('There is no path named "Crop (Capture One)"');
}
loadCropPath("Crop (Capture One)");
try {
var bound = doc.selection.bounds;
cropToSelection(bound[1], bound[0], bound[3], bound[2], false); // delete cropped pixels
} catch (e) {
alert('There was an unexpected error when cropping');
}
app.preferences.rulerUnits = savedRuler;
} else {
alert('A document must be open to use this script!');
}
/******************** FUNCTIONS ********************/
// Courtesy of Chuck Uebele
function cropToSelection(top, left, bottom, right, retainPixels) {
var idCrop = charIDToTypeID("Crop");
var desc11 = new ActionDescriptor();
var idT = charIDToTypeID("T ");
var desc12 = new ActionDescriptor();
var idTop = charIDToTypeID("Top ");
var idPxl = charIDToTypeID("#Pxl");
desc12.putUnitDouble(idTop, idPxl, top);
var idLeft = charIDToTypeID("Left");
var idPxl = charIDToTypeID("#Pxl");
desc12.putUnitDouble(idLeft, idPxl, left);
var idBtom = charIDToTypeID("Btom");
var idPxl = charIDToTypeID("#Pxl");
desc12.putUnitDouble(idBtom, idPxl, bottom);
var idRght = charIDToTypeID("Rght");
var idPxl = charIDToTypeID("#Pxl");
desc12.putUnitDouble(idRght, idPxl, right);
var idRctn = charIDToTypeID("Rctn");
desc11.putObject(idT, idRctn, desc12);
var idAngl = charIDToTypeID("Angl");
var idAng = charIDToTypeID("#Ang");
desc11.putUnitDouble(idAngl, idAng, 0.000000);
var idDlt = charIDToTypeID("Dlt ");
desc11.putBoolean(idDlt, retainPixels); // delete cropped pixels = true | false
var idcropAspectRatioModeKey = stringIDToTypeID("cropAspectRatioModeKey");
var idcropAspectRatioModeClass = stringIDToTypeID("cropAspectRatioModeClass");
var idtargetSize = stringIDToTypeID("targetSize");
desc11.putEnumerated(idcropAspectRatioModeKey, idcropAspectRatioModeClass, idtargetSize);
executeAction(idCrop, desc11, DialogModes.NO);
}
function loadCropPath(pathName) {
var idset = stringIDToTypeID("set");
var desc1606 = new ActionDescriptor();
var idnull = stringIDToTypeID("null");
var ref418 = new ActionReference();
var idchannel = stringIDToTypeID("channel");
var idselection = stringIDToTypeID("selection");
ref418.putProperty(idchannel, idselection);
desc1606.putReference(idnull, ref418);
var idto = stringIDToTypeID("to");
var ref419 = new ActionReference();
var idpath = stringIDToTypeID("path");
ref419.putName(idpath, pathName); // path name
desc1606.putReference(idto, ref419);
var idversion = stringIDToTypeID("version");
desc1606.putInteger(idversion, 1);
var idvectorMaskParams = stringIDToTypeID("vectorMaskParams");
desc1606.putBoolean(idvectorMaskParams, true);
executeAction(idset, desc1606, DialogModes.NO);
}
Copy link to clipboard
Copied
Amazing!
A million thanks, I was looking for this since for ever, you're a saver 🙂
Copy link to clipboard
Copied
Your welcome!
EDIT: Original v1.0 code slightly modified to include error checking for target path.
Copy link to clipboard
Copied
Need script to crop 300 Dpi to path without deleting pixels (without pixel change 300 DPI crop ) pliz Help
sr
script to crop to path without deleting pixels
only convert 72 resolution to 300 Dpi
help me sr
By @Nir Photo Art
I'm not following... What part of the script posted above would you like to modify for your specific needs?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now