3 Replies Latest reply on Feb 18, 2013 1:14 PM by Paul Riggott

    Script to un-mosiac a grid of photos?

    Navarro Parker Level 3

      Is there a script that can chop up an image that is already a mosiac of images? I'm imaginging having PS put each mosiac sqaure on it's own indivdual layer.

       

      A hypothetical example would be an source image like this:    I would define the size of the square before the script runs and it would do the magic.

      20090712_avatar-map.jpeg

        • 1. Re: Script to un-mosiac a grid of photos?
          Paul Riggott Level 6

          This old script might do the job, at the moment it will save as jps but could be changed to suit...

           

           

          #target photoshop
          function main(){
          if(!documents.length) return;
          var dlg=
          "dialog{text:'Script Interface',bounds:[100,100,380,290],"+
          "panel0:Panel{bounds:[10,10,270,180] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
          "title:StaticText{bounds:[60,10,220,40] , text:'File Chop' ,properties:{scrolling:undefined,multiline:undefined}},"+
          "panel1:Panel{bounds:[10,40,250,130] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
          "statictext1:StaticText{bounds:[10,10,111,30] , text:'Accross' ,properties:{scrolling:undefined,multiline:undefined}},"+
          "statictext2:StaticText{bounds:[140,10,230,27] , text:'Down' ,properties:{scrolling:undefined,multiline:undefined}},"+
          "across:DropDownList{bounds:[10,30,100,50]},"+
          "down:DropDownList{bounds:[140,30,230,50]},"+
          "saveFiles:Checkbox{bounds:[10,60,230,80] , text:'Save and Close new files?'}},"+
          "button0:Button{bounds:[10,140,110,160] , text:'Ok' },"+
          "button1:Button{bounds:[150,140,250,160] , text:'Cancel' }}};"
          var win = new Window(dlg,'File Chop');
          if(version.substr(0,version.indexOf('.'))>9){
          win.panel0.title.graphics.font = ScriptUI.newFont("Georgia","BOLD",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.center();
            for(var i=1;i<31;i++){
             win.panel0.panel1.across.add ('item', i);     
             win.panel0.panel1.down.add ('item', i);     
            }
          win.panel0.panel1.across.selection=0;
          win.panel0.panel1.down.selection=0;
          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;
          doc.flatten();
          var tilesAcross = parseInt(win.panel0.panel1.across.selection.index)+1;
          var tilesDown =parseInt(win.panel0.panel1.down.selection.index)+1;
          var tileWidth = parseInt(doc.width/tilesAcross);
          var tileHeight = parseInt(doc.height/tilesDown);
          var SaveFiles = win.panel0.panel1.saveFiles.value;
          ProcessFiles(tilesDown,tilesAcross,tileWidth,tileHeight,SaveFiles);
          app.preferences.rulerUnits = startRulerUnits;      
                } 
             }
            }
          }
          main();
          function ProcessFiles(Down,Across,offsetX,offsetY,SaveFiles){
           try{
          var newName = activeDocument.name.match(/(.*)\.[^\.]+$/)[1];
          }catch(e){var newName="UntitledChop"}
          var Path='';
          try{
          Path =  activeDocument.path;
          }catch(e){Path = "~/Desktop";}
           if(SaveFiles){
          Path = Folder(decodeURI(Path) +"/FileChop");
          if(!Path.exists) Path.create();
               }
          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;
             app.activeDocument.duplicate (NewFileName, true);
              activeDocument.selection.select([[TLX,TLY],[TRX,TRY],[BRX,BRY],[BLX,BLY]], SelectionType.REPLACE, 0, false); 
              executeAction( charIDToTypeID( "Crop" ), undefined, DialogModes.NO );
              app.activeDocument.selection.deselect();
           if(SaveFiles){
          var saveFile = File(decodeURI(Path+"/"+NewFileName+".jpg"));
          SaveJPEG(saveFile, 10);
          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
          }
              activeDocument = documents[0];
          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);
          
           }
           if(SaveFiles){
          Path.execute();
              }
          }
          function SaveJPEG(saveFile, jpegQuality){
          jpgSaveOptions = new JPEGSaveOptions();
          jpgSaveOptions.embedColorProfile = true;
          jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
          jpgSaveOptions.matte = MatteType.NONE;
          jpgSaveOptions.quality = jpegQuality;
          activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
          }
          
          
          • 2. Re: Script to un-mosiac a grid of photos?
            Navarro Parker Level 3

            Works great with CS6 Mac.

             

            How do I increase the max # of tiles in the pop-up menu from 30 to a higher number?

            • 3. Re: Script to un-mosiac a grid of photos?
              Paul Riggott Level 6

              All you need to do is alter this line..

              for(var i=1;i<31;i++){

               

              Change the 31 to any value you like.