Skip to main content
Participating Frequently
April 23, 2017
Answered

Cutting image in parts

  • April 23, 2017
  • 2 replies
  • 5146 views

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!!!

This topic has been closed for replies.
Correct answer SuperMerlin

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);   

    }

};

2 replies

clint flint
Participating Frequently
April 23, 2017

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.

barbara_a7746676
Community Expert
Community Expert
April 23, 2017

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.

efgeepicAuthor
Participating Frequently
April 23, 2017

Is there any possibility, that these slices are automatically as layers in the image file?

SuperMerlin
SuperMerlinCorrect answer
Inspiring
April 23, 2017

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);   

    }

};