7 Replies Latest reply on Dec 16, 2015 6:18 AM by Loic.Aigon

    Please help me for image issue

    tpk1982 Level 4

      Hello,

       

      I need to create an error log report which two same named images overlapped together.

      Screen Shot 2015-12-16 at 1.01.06 PM.png

       

      The above image shows how my indesign file page is. I need the error log report like:

       

      Overlapped images: photo_sample3.jpg

       

      Logic:

       

      I am not sure what logic i need to use to achieve this. But with my knowledge i thought,  i can use image name and image geometric bound value to achieve this. I found one script which gives the page number if any overlap present in that page from this forum.

       

      var overlapArray = new Array();  
      var myPages = app.activeDocument.pages.everyItem().getElements();  
        
      for(i=0; i<myPages.length; i++)  
      {  
          var myPgItems = myPages[i].allPageItems;  
          for(k=0; k<myPgItems.length; k++)  
          {  
           var bounds1 = myPgItems[k].geometricBounds;  
                  for(j=0; j<myPgItems.length; j++)  
                       {  
                         var bounds2 = myPgItems[j].geometricBounds;  
                           if(k==j)  
                           {  
                               continue;  
                           }  
                          var temp = touches(bounds1, bounds2);                     
                          if(temp == true)  
                          {  
                              overlapArray.push(myPages[i].name)  
                          }  
                   }  
               }  
       }  
      alert("overlap Pages: "+overlapArray);  
        
      function touches(bounds1, bounds2)  
      {  
      if (bounds1[2] < bounds2[0]) return false;  
      if (bounds1[0] > bounds2[2]) return false;  
      if (bounds1[1] > bounds2[3]) return false;  
      if (bounds1[3] < bounds2[1]) return false;  
        return true;  
      }   
      

       

      Please help me with script or logic.

       

      Advance thanks,

      Karthi

        • 1. Re: Please help me for image issue
          Loic.Aigon Adobe Community Professional

          I get something but it will only catch one overlapping for a specific image file name. I mean that if you have two sets of overlapping objects for the same link within the same page, only one is analyzed.

           

          Array.prototype.intersect = function ( coordinates ) {
              var n = this.length;
              var nY1, nX1, nY2, nX2; 
              var y1 = coordinates[0];
              var x1 = coordinates[1];
              var y2 = coordinates[2];
              var x2 = coordinates[3];
              
              while ( n-- ) {
                  nY1 = this[n][0];
                  nX1 = this[n][1];
                  nY2 = this[n][2];
                  nX2 = this[n][3];
                  
                  if ( 
                      ( 
                          ( y1>=nY1 && y1<=nY2 )
                          &&
                          (x1>=nX1 && x1<=nX2 ) 
                      )
                      
                      ||
                      
                      (
                          ( y2>=nY1 && y2<=nY2 )
                          &&
                          (x2>=nX1 && x2<=nX2 ) 
                      )
                      
                  ){
                      return true;
                  }
              }
          
              return false;
          }
          function reportOverlaps() {
              var doc,gs, g, n, o = {}, p, pg, pb, lk, lkn, overlaps = [];
              
              if (!app.documents.length) return;
              
              doc = app.activeDocument;
              
              gs = doc.allGraphics;
              
              n = gs.length;
              
              while ( n-- ) {
                  g = gs[n];
                  p = g.parent;
                  pg = p.properties.parentPage;
                  if ( pg instanceof Page ) {
                      pb = p.visibleBounds;
                      
                      lk = g.itemLink;
                      lkn = lk.name;
                      
                      if ( !o[pg.name] ) {
                          o[pg.name] = o[pg.name] || {};
                      }
                      
                      if ( !o[pg.name][lkn] ) {
                          o[pg.name][lkn] = o[pg.name][lkn] || [];
                          o[pg.name][lkn][ o[pg.name][lkn].length ] = pb;
                      }
                      else {
                          var intersect = o[pg.name][lkn].intersect ( pb );
                          intersect && overlaps[ overlaps.length ] = "Pg:"+pg.name+"//"+lkn;
                      }    
                  }
              }
              
              alert( overlaps.length? "Following overlaps where found:\r"+overlaps.join('\r' ) : "No overlaps found" );
          }
          
          reportOverlaps();
          

           

           

          HTH anyway,

           

          Loic

          • 2. Re: Please help me for image issue
            tpk1982 Level 4

            Hi Loic,

             

            Thanks for your reply. It is really helpful to start. Yes it is finding only one

             

            If we modify this script as checking without image name,is it possible it find all overlap images?

             

            Regards,

            Karthi

            • 3. Re: Please help me for image issue
              Laubender Adobe Community Professional & MVP

              Hi Karthi,

              you could loop the links collection, filter out the ones for the images instead to loop the allGraphics array.

               

              link.parent is the placed graphic (if the link points to a graphic file, it could also link to a text file or a media file, sound or movie)

              link.parent.parent is the container frame, that holds the graphic

               

              Note 1: There might be graphics, that have no links (e.g. copy/pasted pixels from PhotoShop).

              Note 2: There could be irregular shapes where the geometricBounds or the visualBounds overlap, but not the images themselves.

              Either from the container frame or a clipping path or because the container will cover more space than the image inside.

               

              Uwe

              • 4. Re: Please help me for image issue
                tpk1982 Level 4

                Hi Uwe,

                 

                Thank for your time. I have limited knowledge in Javascript. Though i will try with your points.

                 

                But my indesign will not contain pasted graphics, i.e. 100% sure. And different container size is not an issue. If overlapped means i need to log the image names in report.

                 

                Thanks,

                Karthi

                • 5. Re: Please help me for image issue
                  Loic.Aigon Adobe Community Professional

                  Hi well,

                  all was needed was a line of code

                   

                  Array.prototype.intersect = function ( coordinates ) {
                      var n = this.length;
                      var nY1, nX1, nY2, nX2; 
                      var y1 = coordinates[0];
                      var x1 = coordinates[1];
                      var y2 = coordinates[2];
                      var x2 = coordinates[3];
                      
                      while ( n-- ) {
                          nY1 = this[n][0];
                          nX1 = this[n][1];
                          nY2 = this[n][2];
                          nX2 = this[n][3];
                          
                          if ( 
                              ( 
                                  ( y1>=nY1 && y1<=nY2 )
                                  &&
                                  (x1>=nX1 && x1<=nX2 ) 
                              )
                              
                              ||
                              
                              (
                                  ( y2>=nY1 && y2<=nY2 )
                                  &&
                                  (x2>=nX1 && x2<=nX2 ) 
                              )
                              
                          ){
                              return true;
                          }
                      }
                  
                      return false;
                  }
                  function reportOverlaps() {
                      var doc,gs, g, n, o = {}, p, pg, pb, lk, lkn, overlaps = [];
                      
                      if (!app.documents.length) return;
                      
                      doc = app.activeDocument;
                      
                      gs = doc.allGraphics;
                      
                      n = gs.length;
                      
                      while ( n-- ) {
                          g = gs[n];
                          p = g.parent;
                          pg = p.properties.parentPage;
                          if ( pg instanceof Page ) {
                              pb = p.visibleBounds;
                              
                              lk = g.itemLink;
                              lkn = lk.name;
                              
                              if ( !o[pg.name] ) {
                                  o[pg.name] = o[pg.name] || {};
                              }
                              
                              if ( !o[pg.name][lkn] ) {
                                  o[pg.name][lkn] = o[pg.name][lkn] || [];
                                  o[pg.name][lkn][ o[pg.name][lkn].length ] = pb;
                              }
                              else {
                                  var intersect = o[pg.name][lkn].intersect ( pb );
                                  intersect && overlaps[ overlaps.length ] = "Pg:"+pg.name+"//"+lkn;
                                  o[pg.name][lkn][ o[pg.name][lkn].length ] = pb;
                              }    
                          }
                      }
                      
                      alert( overlaps.length? "Following overlaps where found:\r"+overlaps.join('\r' ) : "No overlaps found" );
                  }
                  
                  reportOverlaps();
                  

                   

                   

                  Loic

                  www.ozalto.com

                  • 6. Re: Please help me for image issue
                    tpk1982 Level 4

                    Hi Loic,

                     

                    Awesome!!!!

                     

                    It is working fine. Thank you soooooooo much

                     

                    Regards,

                    Karthi

                    • 7. Re: Please help me for image issue
                      Loic.Aigon Adobe Community Professional

                      Glad it helped

                       

                      loïc

                      www.ozalto.com