I have a large PSB file (33600x19200px) and I need to write a script to export sections of this image as a series of images. What would the best approach be ?
Initially I thought about scripting slices and exporting, but Save for Web is diabled for this resolution.
Another option I thought was this:
- loop through each section I need to export
- make a selection
- copy pixels
- create a new document
- paste pixels
- save for the web with the format and name I need
- close the document without saving
- goto 1
Is this the best approach ? What are your suggestions ?
Update:
Here's my script with the steps above:
#target photoshop
var doc = app.activeDocument;
var sel = doc.selection;//main document selection
var rows = 70;
var cols = 40;
var cell = 240;//size of a cell/display image/region of interest
var space=240; //space in between cells
var dname = doc.name.substr(0,doc.name.length-4);
var dir = doc.path.toString()+"/";
var dpi72 = 182.88036576073152146304292608585;
var options = new ExportOptionsSaveForWeb();
options.format = SaveDocumentType.JPEG;
options.quality = 75;
//*
for(var y = 0; y < cols; y++){
for(var x = 0 ; x < rows; x++){
var xpos = (x * (cell+space))+((1-y%2) * space);//+ di-grid offset
var ypos = (y * (cell+space));
try{
sel.select([[xpos,ypos],[xpos+cell,ypos],[xpos+cell,ypos+cell],[xpos,ypos+cell]],SelectionType.REPLACE,0,false);
sel.copy(true);
var nname = dname + "_"+((x+1)) + "_" + ((y+1));
//$.writeln("["+x+"]["+y+"]" +nname +"\n"+sel.bounds);
//*
var small = app.documents.add(cell,cell,dpi72,dname,NewDocumentMode.RGB,DocumentFill.WHITE);
app.activeDocument = small;
small.paste();
small.exportDocument (new File(dir + "/" + nname + ".jpg"), ExportType.SAVEFORWEB, options);
small.close(SaveOptions.DONOTSAVECHANGES);
app.activeDocument = doc;
//*/
}catch(err){
x = rows;
y = cols;
alert(err);
}
}
}
The script works, but it's a bit slow. Is my approach ok or is there a faster way to do this ?