Copy link to clipboard
Copied
I have an image, i want to get 9 by 7 equal rectangles as layers, the size of the image is different.
this could be portrait as also landscape.
the 63 rectangles should be in 63 layers.
Thanks to the experts!!!
Nope, but you could run this script and it will create your layers...
...#target photoshop
if(documents.length){
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
doc = app.activeDocument;
app.displayDialogs = DialogModes.NO;
doc.flatten();
var tilesAcross =9;
var tilesDown =7;
var tileWidth = parseInt(doc.width/tilesAcross);
var tileHeight = parseInt(doc.height/tilesDown);
ProcessFiles(tilesDown,tilesAcross,tileWidth,tileHeight);
app.preferences.rulerUnits = startRulerUnits;
Copy link to clipboard
Copied
View > New Guide Layout.
Select Slice tool.
Click Slices from Guides.
File > Export > Save for Web.
Choose optimization settings and click Save. Photoshop will put all slices into a folder, each as a separate image.
Copy link to clipboard
Copied
Is there any possibility, that these slices are automatically as layers in the image file?
Copy link to clipboard
Copied
Nope, but you could run this script and it will create your layers...
#target photoshop
if(documents.length){
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
doc = app.activeDocument;
app.displayDialogs = DialogModes.NO;
doc.flatten();
var tilesAcross =9;
var tilesDown =7;
var tileWidth = parseInt(doc.width/tilesAcross);
var tileHeight = parseInt(doc.height/tilesDown);
ProcessFiles(tilesDown,tilesAcross,tileWidth,tileHeight);
app.preferences.rulerUnits = startRulerUnits;
}
function ProcessFiles(Down,Across,offsetX,offsetY){
try{
var newName = activeDocument.name.match(/(.*)\.[^\.]+$/)[1];
}catch(e){var newName="UntitledChop"}
TLX = 0; TLY = 0; TRX = offsetX; TRY = 0;
BRX = offsetX; BRY = offsetY; BLX = 0; BLY = offsetY;
for(var a = 0; a < Down; a++){
for(var i = 0;i <Across; i++){
var NewFileName = newName +"#"+a+"-"+i;
activeDocument.selection.select([[TLX,TLY],[TRX,TRY],[BRX,BRY],[BLX,BLY]], SelectionType.REPLACE, 0, false);
executeAction( charIDToTypeID( "CpTL" ), undefined, DialogModes.NO );
activeDocument.activeLayer.name = NewFileName;
app.activeDocument.selection.deselect();
activeDocument.activeLayer = activeDocument.artLayers.getByName("Background");
TLX = offsetX * (i+1) ; TRX = TLX + offsetX; BRX = TRX; BLX = TLX;
}
TLX = 0; TLY = offsetY * (a +1); TRX = offsetX; TRY = offsetY * (a +1);
BRX = offsetX; BRY = TRY + offsetY; BLX = 0; BLY = (offsetY * (a +1)+offsetY);
}
};
Copy link to clipboard
Copied
this is nearly the best result. i have some gaps in the image.
Please take a look at the image.
Counter is perfect.
Copy link to clipboard
Copied
Are you viewing at 100% (1:1)? If not, view at 100% and report back.
If you merge all layers to a single layer (not flatten), do the lines disappear?
For future reference: a similar but different script – Photoshop script to cut images into new layers of a given size · GitHub
/* modification of a script by Oisin Conolly (digitalbiscuits.co.uk),
* found on StackOverflow (http://goo.gl/Ko9Ik) */
// x and y size of the slices we want to take
var xSize = 110;
var ySize = 30;
// set the ruler type
if (app.preferences.rulerUnits != Units.PIXELS) {
app.preferences.rulerUnits = Units.PIXELS;
}
// keep a reference to the document and original layer
var docRef = app.activeDocument;
var layerRef = docRef.activeLayer;
for (y = 0; y<docRef.height; y+=ySize) {
for (x = 0; x<docRef.width; x+=xSize) {
// activate the original layer
docRef.activeLayer = layerRef;
// make the selection
docRef.selection.select(Array (Array(x, y), Array(x, y+ySize), Array(x+xSize,y+ySize), Array(x+xSize,y)), SelectionType.REPLACE, 0, false);
// copy the selection
docRef.selection.copy();
// create new layer
docRef.artLayers.add();
// deselect so that the paste hits 0,0 like we want it to for the animation
docRef.selection.deselect();
// and paste it
docRef.paste();
}
}
Copy link to clipboard
Copied
Thank you, looked at it on 100%, no gaps.
Best regards.
Copy link to clipboard
Copied
View it at 100% and you will see the gaps dissapear.
Copy link to clipboard
Copied
There's the Photoshop command File > Scripts > Load Files into Stack, which will combine multiple images into a layered file. The resulting image will be the canvas size of one sliced image.
Copy link to clipboard
Copied
Thanks for this answer:)
Copy link to clipboard
Copied
It's certainy possible to slice your image into sections and then save them out as slices. Does this video help?
how to slice picture in photoshop - YouTube
this will save each image seperately in a folder of your choice.
Placing them on individual layers would probably have to be done manually from there.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now