Skip to main content
Participant
January 5, 2010
Question

I have a 440 pixel (22x20) image. How do i create a seperate psd file from each pixel by scripting?

  • January 5, 2010
  • 1 reply
  • 574 views

I have a 440 pixel (22x20) image. Is there an easy way to create a seperate psd file from each pixel by scripting? I need to do this with a lot of 440 pixel files.

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
January 5, 2010

This should do it, the document must be open in Photoshop.


#target photoshop
function main(){
var dlg=
"dialog{text:'Script Interface',bounds:[100,100,630,270],"+
"panel1:Panel{bounds:[10,10,520,160] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"title:StaticText{bounds:[150,10,320,40] , text:'Pixel Dump' ,properties:{scrolling:undefined,multiline:undefined}},"+
"statictext1:StaticText{bounds:[10,40,300,60] , text:'Please select output folder' ,properties:{scrolling:undefined,multiline:undefined}},"+
"folder:EditText{bounds:[10,70,400,90] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"browse:Button{bounds:[410,70,501,91] , text:'Browse' },"+
"Process:Button{bounds:[10,120,190,141] , text:'Process' },"+
"button2:Button{bounds:[320,120,500,141] , text:'Cancel' },"+
"},"+
"};"
var win = new Window(dlg,'Pixel Dump');
win.panel1.folder.enabled=false;
win.panel1.browse.onClick = function() {
outputFolder = Folder.selectDialog("Please select the output folder");
if(outputFolder !=null){
  win.panel1.folder.text =  decodeURI(outputFolder.fsName);
  }
}
if(version.substr(0,version.indexOf('.'))>9){
win.panel1.title.graphics.font = ScriptUI.newFont("Arial","BOLDITALIC",20);
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [1.00, 1.00, 1.00, 1]);
g.backgroundColor = myBrush;
var myPen =g.newPen (g.PenType.SOLID_COLOR, [1.00, 0.00, 0.00, 1],lineWidth=1);
}
win.panel1.Process.onClick = function(){
if(win.panel1.folder.text == '') {
  alert("no output folder selected");
  return;
  }
win.close(1);
}
win.center();

var done = false;
    while (!done) {
      var x = win.show();
      if (x == 0 || x == 2) {
        win.canceled = true;
        done = true;
      } else if (x == 1) {
        done = true;
        {
if(!documents.length)return;
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
doc = app.activeDocument;
app.displayDialogs = DialogModes.NO;
var tilesAcross = activeDocument.width.value;
var tilesDown =activeDocument.height.value;
var tileWidth = parseInt(doc.width/tilesAcross);
var tileHeight = parseInt(doc.height/tilesDown);
ProcessFiles(tilesDown,tilesAcross,tileWidth,tileHeight,outputFolder);
app.preferences.rulerUnits = startRulerUnits;     
      }
   }
  }
}
main();
function ProcessFiles(Down,Across,offsetX,offsetY,outputFolder){
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++){
   app.activeDocument.duplicate (newName +"#"+a+"-"+i, true);
    activeDocument.selection.select([[TLX,TLY],[TRX,TRY],[BRX,BRY],[BLX,BLY]], SelectionType.REPLACE, 0, false);
    executeAction( charIDToTypeID( "Crop" ), undefined, DialogModes.NO );
    var saveFile=File(outputFolder +"/"+ newName +"#"+a+"-"+i +".psd");
    app.activeDocument.selection.deselect();
    SavePSD(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
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);

}
}
function SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true; 
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}

Participant
January 5, 2010

Hi Paul,

Thank you so much!

I am new to photoshop scripting. So how do I incorporate this piece of code in the program?

Joris

Paul Riggott
Inspiring
January 5, 2010

Open ExtenScript Toolkit, this gets installed with Photoshop and can be found:-
PC: C:\Program Files\Adobe\Adobe Utilities
MAC: <hard drive>/Applications/Utilities/Adobe Utilities
Paste in the code to a new window and save to:-

PC: C:\Program Files\Adobe\Adobe Photoshop CS#\Presets\Scripts
MAC: <hard drive>/Applications/Adobe Photoshop CS#/ Presets/Scripts

NB: If you are running Vista or Windows 7 you don't have the permissions to save directly into these folders, you will need to save it elsewhere and copy it into the above folder.

To use: If Photoshop was open, close and restart it.
Open your document
File - Scripts - select the script
It will give you a User Interface for the output folder, and click Process
Good luck.