Copy link to clipboard
Copied
I have a label that’s 13.5” wide x 7.75” high and I want to automate several 2” wide extractions in 10% increments along the width. I’m doing it manually, but it's messy and I suspect there is probably a better way from which I can create an action that also prompts for dimensions of different size labels. I’d greatly appreciate suggestions and welcome any questions.
Thank you
CW
Copy link to clipboard
Copied
You might try the slice tool. Right click and and select Divide Slice. Save for web to save the slices individually.
Copy link to clipboard
Copied
I like the slice tool, but I don't think slices can only be selected within an image--just from side-to-side or top-to-bottom.
Copy link to clipboard
Copied
If you can do that systemically manually in Photoshop. You would most likely can automate your processing using Photoshop scripting. In a Photoshop Scripting you can use logic to calculate the size the 10 extractions need to be. Then create the 10 extraction like you do manually using a programed processor like your manual procedure. Scripting require programming knowledge which you most likelt do not have.
You can also use menu View>New Guide laueout toe setd guides the the extractions. You may fine the following thread useful. https://community.adobe.com/t5/photoshop/how-to-slice-a-very-large-poster/m-p/10998357?page=1
Copy link to clipboard
Copied
"I have a label that’s 13.5” wide x 7.75” high and I want to automate several 2” wide extractions in 10% increments along the width."
10% increments would be 1.35" wide.
If you wish to have something that is not based on specific/absolute sizes, then working in relative units of % would be more flexible.
I'm pretty sure that I have a script that can automate splitting an image into layers...
Copy link to clipboard
Copied
//community.adobe.com/t5/photoshop/how-to-slice-a-very-large-poster/m-p/10998357
// split Image to layer according to guides;
// 2015, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var myResolution = myDocument.resolution;
var theLayer = myDocument.activeLayer;
var layerID = getLayerId(theLayer);
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// check guides;
var theVer = new Array;
var theHor = new Array;
var theNumber = myDocument.guides.length;
for (var m = 0; m < theNumber; m++) {
if (myDocument.guides[m].direction == Direction.HORIZONTAL) {
theHor.push(myDocument.guides[m].coordinate)
};
if (myDocument.guides[m].direction == Direction.VERTICAL) {
theVer.push(myDocument.guides[m].coordinate)
};
};
// sort and add beginning and end;
theHor = treatGuideArray(theHor, app.activeDocument.height);
theVer = treatGuideArray(theVer, app.activeDocument.width);
$.writeln(theHor.join("\n") + "\n\n\n" + theVer.join("\n"));
// create selections;
for (var y = 0; y < theHor.length - 1; y++) {
var Y1 = theHor[y];
var Y2 = theHor[y + 1];
for (var x = 0; x < theVer.length - 1; x++) {
try {
var X1 = theVer[x];
var X2 = theVer[x + 1];
rectangularSelection([Y1, X1, Y2, X2], false);
// layer via copy;
var id14 = charIDToTypeID("CpTL");
executeAction(id14, undefined, DialogModes.NO);
// add mask;
intersectedLayerMask(layerID)
} catch (e) { };
// reselct layer;
myDocument.activeLayer = theLayer;
};
};
activeDocument.selection.deselect();
// reset the ruler units;
app.preferences.rulerUnits = originalRulerUnits
};
////////////////// the functions //////////////////
////// treat array //////
function treatGuideArray(theArray, theExtreme) {
theArray.sort(function (a, b) {
return a - b
});
if (Number(theArray[theArray.length - 1]) != theExtreme) {
theArray.push(theExtreme)
};
if (Number(theArray[0]) != 0) {
theArray.unshift(new UnitValue(0, "pt"))
};
theArray.sort(function (a, b) {
return a - b
});
return theArray;
};
////// rectangular selection //////
function rectangularSelection(theBounds, add) {
// =======================================================
if (add == false || add == undefined) {
var idsetd = charIDToTypeID("setd")
} else {
var idsetd = charIDToTypeID("AddT")
};
var desc55 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref11 = new ActionReference();
var idChnl = charIDToTypeID("Chnl");
var idfsel = charIDToTypeID("fsel");
ref11.putProperty(idChnl, idfsel);
desc55.putReference(idnull, ref11);
var idT = charIDToTypeID("T ");
var desc56 = new ActionDescriptor();
var idTop = charIDToTypeID("Top ");
var idRlt = charIDToTypeID("#Rlt");
desc56.putUnitDouble(idTop, idRlt, theBounds[0]);
var idLeft = charIDToTypeID("Left");
var idRlt = charIDToTypeID("#Rlt");
desc56.putUnitDouble(idLeft, idRlt, theBounds[1]);
var idBtom = charIDToTypeID("Btom");
var idRlt = charIDToTypeID("#Rlt");
desc56.putUnitDouble(idBtom, idRlt, theBounds[2]);
var idRght = charIDToTypeID("Rght");
var idRlt = charIDToTypeID("#Rlt");
desc56.putUnitDouble(idRght, idRlt, theBounds[3]);
var idRctn = charIDToTypeID("Rctn");
desc55.putObject(idT, idRctn, desc56);
executeAction(idsetd, desc55, DialogModes.NO);
};
// by mike hale, via paul riggott;
function getLayerId(theLayer) {
// http://forums.adobe.com/message/1944754#1944754
app.activeDocument.activeLayer = theLayer;
//Assumes activeDocument and activeLayer
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
d = executeActionGet(ref);
return d.getInteger(charIDToTypeID('LyrI'));
};
////// load transparency, ontersect with layer mask ofd another layer, add layer mask //////
function intersectedLayerMask(layerID) {
var idChnl = charIDToTypeID("Chnl");
// =======================================================
var idsetd = charIDToTypeID("setd");
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref1 = new ActionReference();
var idfsel = charIDToTypeID("fsel");
ref1.putProperty(idChnl, idfsel);
desc2.putReference(idnull, ref1);
var idT = charIDToTypeID("T ");
var ref2 = new ActionReference();
var idTrsp = charIDToTypeID("Trsp");
ref2.putEnumerated(idChnl, idChnl, idTrsp);
desc2.putReference(idT, ref2);
executeAction(idsetd, desc2, DialogModes.NO);
// =======================================================
var idIntr = charIDToTypeID("Intr");
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref3 = new ActionReference();
var idMsk = charIDToTypeID("Msk ");
ref3.putEnumerated(idChnl, idChnl, idMsk);
var idLyr = charIDToTypeID("Lyr ");
ref3.putIdentifier(idLyr, layerID);
desc3.putReference(idnull, ref3);
var idWith = charIDToTypeID("With");
var ref4 = new ActionReference();
var idfsel = charIDToTypeID("fsel");
ref4.putProperty(idChnl, idfsel);
desc3.putReference(idWith, ref4);
executeAction(idIntr, desc3, DialogModes.NO);
// =======================================================
var idMk = charIDToTypeID("Mk ");
var desc4 = new ActionDescriptor();
var idNw = charIDToTypeID("Nw ");
desc4.putClass(idNw, idChnl);
var idAt = charIDToTypeID("At ");
var ref5 = new ActionReference();
var idMsk = charIDToTypeID("Msk ");
ref5.putEnumerated(idChnl, idChnl, idMsk);
desc4.putReference(idAt, ref5);
var idUsng = charIDToTypeID("Usng");
var idUsrM = charIDToTypeID("UsrM");
var idRvlS = charIDToTypeID("RvlS");
desc4.putEnumerated(idUsng, idUsrM, idRvlS);
executeAction(idMk, desc4, DialogModes.NO);
};
Copy link to clipboard
Copied
//community.adobe.com/t5/photoshop/dividing-big-document-to-smaller-ones/m-p/9311087
// split image into x times y segments and save them as psds;
// 2017, use it at your own risk;
// 2020 - Modified by Stephen Marsh, adding prompts, save alert, saved doc test.
#target photoshop
/* Start Unsaved Document Error Check - Part A: Try */
unSaved();
function unSaved() {
try {
activeDocument.path;
/* Finish Unsaved Document Error Check - Part A: Try */
/* Main Code Start */
if (app.documents.length > 0) {
var originalUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// document;
var myDocument = app.activeDocument;
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
var theCopy = myDocument.duplicate("copy", false);
// Loop the X input prompt until a number is entered
var theXinput;
while (isNaN(theXinput = prompt("Enter a whole number:", "3")));
// Convert decimal input to integer
var theXtoInteger = parseInt(theXinput);
// Final result
var theX = theXtoInteger;
// Loop the Y input prompt until a number is entered
var theYinput;
while (isNaN(theYinput = prompt("Enter a whole number:", "3")));
// Convert decimal input to integer
var theYtoInteger = parseInt(theYinput);
// Final result
var theY = theYtoInteger;
// Canvas Division
var xFrac = myDocument.width / theX;
var yFrac = myDocument.height / theY;
// PSD options;
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
psdOpts.layers = true;
psdOpts.spotColors = true;
// create folder;
var folderName = thePath + "/" + theName + "_" + theX + "x" + theY;
if (Folder(folderName).exists === false) {
Folder(folderName).create()
}
// save PSD files;
for (var n = 1; n <= theY; n++) {
for (var m = 1; m <= theX; m++) {
cropTo((m - 1) * xFrac, (n - 1) * yFrac, m * xFrac, n * yFrac);
var theNewName = theName + "_" + bufferNumberWithZeros(m, 3) + "_" + bufferNumberWithZeros(n, 3);
theCopy.saveAs((new File(folderName + "/" + "_" + theNewName + ".psd")), psdOpts, true);
theCopy.activeHistoryState = theCopy.historyStates[0];
}
}
theCopy.close(SaveOptions.DONOTSAVECHANGES);
// reset;
app.preferences.rulerUnits = originalUnits;
}
////// buffer number with zeros //////
function bufferNumberWithZeros(number, places) {
var theNumberString = String(number);
for (var o = 0; o < (places - String(number).length); o++) {
theNumberString = String("0" + theNumberString)
}
return theNumberString
}
////// crop //////
function cropTo(x1, y1, x2, y2) {
// =======================================================
var desc7 = new ActionDescriptor();
var desc8 = new ActionDescriptor();
var idPxl = charIDToTypeID("#Pxl");
desc8.putUnitDouble(charIDToTypeID("Top "), idPxl, y1);
desc8.putUnitDouble(charIDToTypeID("Left"), idPxl, x1);
desc8.putUnitDouble(charIDToTypeID("Btom"), idPxl, y2);
desc8.putUnitDouble(charIDToTypeID("Rght"), idPxl, x2);
var idRctn = charIDToTypeID("Rctn");
desc7.putObject(charIDToTypeID("T "), idRctn, desc8);
desc7.putUnitDouble(charIDToTypeID("Angl"), charIDToTypeID("#Ang"), 0.000000);
desc7.putBoolean(charIDToTypeID("Dlt "), false);
desc7.putEnumerated(stringIDToTypeID("cropAspectRatioModeKey"), stringIDToTypeID("cropAspectRatioModeClass"), stringIDToTypeID("pureAspectRatio"));
desc7.putBoolean(charIDToTypeID("CnsP"), false);
executeAction(charIDToTypeID("Crop"), desc7, DialogModes.NO);
}
alert('PSD Files saved to: ' + folderName);
/* Main Code Finish */
/* Start Unsaved Document Error Check - Part B: Catch */
} catch (err) {
alert('An image must be both open and saved before running this script!')
}
}
/* Finish Unsaved Document Error Check - Part B : Catch */
Copy link to clipboard
Copied
Stephen, I tried your scrip. Although it wasn't what I was looking for, it's great for its intended use, dissecting an image into a given matrix of files. At some point it'll be handy. Thank you.
Copy link to clipboard
Copied
// https://forums.adobe.com/thread/2374785
// split image into x times y segments and save them as jpgs;
// 2017, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var originalUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// document;
var myDocument = app.activeDocument;
var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
var theCopy = myDocument.duplicate("copy", true);
// the numbers;
var theX = 9;
var theY = 13;
var xFrac = myDocument.width/theX;
var yFrac = myDocument.height/theY;
// psd options;
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
psdOpts.layers = true;
psdOpts.spotColors = true;
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 9;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
// create folder;
var folderName = thePath+"/"+theName+"_"+theX+"x"+theY;
if (Folder(folderName).exists == false) {Folder(folderName).create()};
//save jpgs;
for (var n = 1; n <= theY; n++) {
for (var m = 1; m <= theX; m++) {
cropTo((m-1)*xFrac, (n-1)*yFrac, m*xFrac, n*yFrac);
var theNewName = theName+"_"+bufferNumberWithZeros(m, 3)+"_"+bufferNumberWithZeros(n, 3);
theCopy.saveAs((new File(folderName+"/"+"_"+theNewName+".jpg")),jpegOptions,true);
theCopy.activeHistoryState = theCopy.historyStates[0];
//executeAction( charIDToTypeID("undo"), undefined, DialogModes.NO );
}
};
theCopy.close(SaveOptions.DONOTSAVECHANGES);
// reset;
app.preferences.rulerUnits = originalUnits;
};
////// buffer number with zeros //////
function bufferNumberWithZeros (number, places) {
var theNumberString = String(number);
for (var o = 0; o < (places - String(number).length); o++) {
theNumberString = String("0" + theNumberString)
};
return theNumberString
};
////// crop //////
function cropTo (x1, y1, x2, y2) {
// =======================================================
var desc7 = new ActionDescriptor();
var desc8 = new ActionDescriptor();
var idPxl = charIDToTypeID( "#Pxl" );
desc8.putUnitDouble( charIDToTypeID( "Top " ), idPxl, y1 );
desc8.putUnitDouble( charIDToTypeID( "Left" ), idPxl, x1);
desc8.putUnitDouble( charIDToTypeID( "Btom" ), idPxl, y2 );
desc8.putUnitDouble( charIDToTypeID( "Rght" ), idPxl, x2 );
var idRctn = charIDToTypeID( "Rctn" );
desc7.putObject( charIDToTypeID( "T " ), idRctn, desc8 );
desc7.putUnitDouble( charIDToTypeID( "Angl" ), charIDToTypeID( "#Ang" ), 0.000000 );
desc7.putBoolean( charIDToTypeID( "Dlt " ), false );
desc7.putEnumerated( stringIDToTypeID( "cropAspectRatioModeKey" ), stringIDToTypeID( "cropAspectRatioModeClass" ), stringIDToTypeID( "pureAspectRatio" ) );
desc7.putBoolean( charIDToTypeID( "CnsP" ), false );
executeAction( charIDToTypeID( "Crop" ), desc7, DialogModes.NO );
};
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
Copy link to clipboard
Copied
They seem to have a manual way to make their 2" wide extractions in 10% increments. While 10x2" is 20" inches not 13.5". The Op did not state that there are no overlap areas in the extractions. 10x2" can equal 13.5" when you have overlapping areas. I have seen that type of extracting done for crating large billboard and wall murals where the extensions are blown up and printed. The print out pieces can be easily aligned and glued to the backing board or wall. seams will not be noticeable if the alignment is not perfect. Without overlay alignment must be perfect which is hard to do if you are dealing with large enlargements. 20"-13.5" = 6.5 " overlap 6.5"/9=0.7" overlaps.
Copy link to clipboard
Copied
Good point, I was obviously thinking of even splits without overlap, so if this is the case something else may be required.
Copy link to clipboard
Copied
Explaining a little about the project should be helpful. It’s a virtual photography project that is to emulate photographing a cylindrical bottle as it rotates 360 degrees. In the example, 10 frames are required as input to a “spin” app, such as https://www.webrotate360.com/. There are many environmental challenges to photographing 360 spins, such as unintentional malformed bottles, too much glare or reflection, dirt and dust, and imperfect alignment in the scene. The cost of editing images for these kinds of issues often impairs profitability when clients will not budget for it. So, it's virtual photography to the rescue for products that are bottles with labels.
The images that are extracted from a label may be thought of as frames that are to be layered onto an image of a bottle retrieved from Adobe Stock, for example. Each merged image will look slightly different, emulating the bottle turning. There is a little more processing to do such a slight warp of the label, slight light leaks, but these can be included in an Action and applied to all images.
The case for virtual photography really stands out when 36 or 72 or more images are required, particularly for discerning clients that will not accept the kind of faults shown in this image: https://snap36.com/360-gallery/wine-bottle/. (Not my image or work, btw).
Please don’t hesitate to ask any questions or make suggestions.
Thank you for thinking about my post.
CW