All nice answers, thanks for the contribution.
As I said, I wondering if there was something out there for Photoshop.
For documentation purposes here is a little script I wrote:
var doc = app.activeDocument;
var arranger = makeDialog();
arranger .arrange.onClick = function(){
if(isNaN(parseInt(arranger.w.text)) || isNaN(parseInt(arranger.h.text)) || isNaN(parseInt(arranger.c.text)) || isNaN(parseInt(arranger.r.text))){
alert('Yo! Can you feed \' dis dialog some integer numbers ?\n For Real!');
}else{
sliceLayer(parseInt(arranger.w.text),parseInt(arranger.h.text),parseInt(arranger.r.text),parseInt(arranger.c.text));
}
arranger.close();
}
arranger.show();
function sliceLayer(w,h,r,c){
var hw = w * 0.5;
var hh = h * 0.5;
var l0 = doc.activeLayer;
for(var j = 0 ; j < r ; j++){
for(var i = 0 ; i < c; i++){
var x = i * w; //edited
var y = j * h; //here
//select
doc.selection.select([[x,y],[x+w,y],[x+w,y+h],[x,y+h]]);
//new layer via cut
doc.selection.cut();
var layer = doc.artLayers.add();
doc.paste();
//move
//$.writeln('translate x: '+(y)+', y: '+(x));
// move layer with relative coordinates
// layer.translate(y,x);
// move layer with absolute coordinates
MoveLayerTo( layer, x, y );
doc.activeLayer = l0;
}
}
l0.remove();//remove original layer(now empty)
}
function makeDialog(){
var dialog = new Window('dialog','Slice and Dice');
dialog.frameLocation = [300,300];
dialog.w = dialog.add('edittext',undefined,'Selection width');
dialog.w.prefferedSize = [200,50];
dialog.h = dialog.add('edittext',undefined,'Selection height');
dialog.h.prefferedSize = [200,50];
dialog.c = dialog.add('edittext',undefined,'Grid Columns(V sections)');
dialog.c.prefferedSize = [200,50];
dialog.r = dialog.add('edittext',undefined,'Grid Rows(H sections)');
dialog.r.prefferedSize = [200,50];
dialog.arrange = dialog.add('button',undefined,'Chop Chop');
return dialog;
}
//******************************************
// MOVE LAYER TO
// Author: Max Kielland
//
// Moves layer fLayer to the absolute
// position fX,fY. The unit of fX and fY are
// the same as the ruler setting.
function MoveLayerTo(fLayer,fX,fY) {
var Position = fLayer.bounds;
Position[0] = fX - Position[0];
Position[1] = fY - Position[1];
fLayer.translate(-Position[0],-Position[1]);
}
If you save this in Photoshop/Presets/Scripts as a .jsx file, you should be able to access it through Scripts in the File menu. You can also use File -> Scripts -> Browse... with the script anywhere on your computer.
It will ask for four things:
- Selection width — How wide you want each block in the grid to be
- Selection height — How tall you want each block in the grid to be
- Grid Columns (V sections) — How many columns there should be once it's split up
- Grid Rows (H sections) — How many rows there should be once it's split up
If you get an error about the document not being found, you just need to open an image first before running it.
The problem with this JSX approach is, it is a bit slow for large subdivisions (100x100).
I'm guessing it will be faster to try with MATLAB/Photoshop communication, but I'll skip that for now.
Achieved the same goal in actionscript 3 using copyPixels() and it's pretty fast.
thanks, but I'm afraid that's way to long winded, I'm to lazy for that :) – George Profenza – 2010-01-31T01:38:43.143