9 Replies Latest reply on Sep 8, 2018 7:16 AM by Stephen_A_Marsh

    Relink to new image file by pixel-by-pixel comparison

    kajzica Level 1


      We have 110 indd docs all over the place on servers-workstations with placed 3150 png/tif qr codes. So around 30 links per file.

      Want to relink placed images to new share folder with only pngs, but now new images have different names but same content. File size is not option.

      Is it possible via indesign scripting to relink but that indesign search for most similar image in new folder and relink old image automatically? pixel-by-pixel comparison or similar.



        • 1. Re: Relink to new image file by pixel-by-pixel comparison
          Laubender Adobe Community Professional & MVP

          Hi kajzica ,

          the comparison part pixel-by-pixel could be done by PhotoShop.
          With InDesign I see no way. Accessing PhotoShop from InDesign can be done by BridgeTalk.

          Here an example with a snippet that opens an image placed with InDesign in PhotoShop:


          ( function()
              if( app.documents.length == 0 ){ return };
              if( app.documents[0].allGraphics.length == 0 ){ return };
              // Have one placed and linked image in the active document:
              var image = app.documents[0].allGraphics[0];
              // Get the file path of the image:
              var imagePath = image.itemLink.filePath;
              // Test if the image is available:
              if( !File( imagePath ).exists ){ alert( "Error! Image does not exist!"); return };
              // We need the BridgeTalk object to talk to PhotoShop:
              var bt = new BridgeTalk;   
              bt.target = "photoshop";
              // A more compact way to write the script code for PhotoShop with triple fencing.
              // PhotoShop will open the image:
              var psdScript =
              app.displayDialogs = DialogModes.NO;
              var myPsDoc = app.open(File("''' + imagePath + '''"));
              // insert code for comparing this image with another one already open or with an image you open after this.
              app.displayDialogs = DialogModes.ALL;
              bt.body = psdScript;
              //Idea: Kasyan Servetsky
              bt.onError = function(errObj)
                  alert( "Error: " + errObj.body );
              //Idea: Kasyan Servetsky
              bt.onResult = function(resObj) {};
              bt.send( 30 );
          }() )


          How could a comparison of pixels be done with PhotoShop?


          1. Load both images as layer to one PhotoShop file.

          2. Do layer effect Difference on the top layer.

          3. Merge the two layers to the background layer.

          4. Exploit the Histogram feature.


          You should see only one value that is not zero as first entry in the histogram array.

          In effect the background layer is totally black with RGB 0,0,0. With a CMYK image the perfect result would be black with 100 C, 100 M, 100 Y, 100 K.


          If not there is a difference in the two original images.


          For details regarding PhotoShop scripting see:

          Adobe Photoshop Scripting

          Photoshop Scripting



          And of course Davide Barranca's "Professional PhotoShop Scripting"




          • 2. Re: Relink to new image file by pixel-by-pixel comparison
            Laubender Adobe Community Professional & MVP

            Here a PhotoShop script sample that works with histogram of individual channels in a CMYK image.

            Discussion is in German.


            Photoshop CC - Kanäle auf Verwendung prüfen




            • 3. Re: Relink to new image file by pixel-by-pixel comparison
              kajzica Level 1

              will try to find solution and report back, as always do.

              in midtime, any script which can relink to new link from excel table? column a old name and path, column b new name and path?



              OLD LINKNEW LINK
              • 4. Re: Relink to new image file by pixel-by-pixel comparison
                Laubender Adobe Community Professional & MVP

                Hi kajzica ,

                see into Kasyan Servetsky's script repository here:

                Scripts sorted by categories for InDesign

                Scroll to category Link.



                • 5. Re: Relink to new image file by pixel-by-pixel comparison
                  kajzica Level 1

                  Kasyan page is golden box for any dtp user. But no script for change from to.


                  I have "old" links with name 01.tif, 02.tif...............11.tif.....99.tif

                  need to relink it to different folder/name and with new name like 22256_bbbb_3_444_1.png, 22256_bbbb_3_444_2.png

                  22256_bbbb_3_444_ is prefix which have new image name. last number is always same.

                  As you can see, script need to ignore first 0, add virtual prefix and relink it to this real new name in new folder. i can remove 0 from 1-9.

                  1.tif is now linked to prefix_1.png

                  10.tif is now linked to prefix_10.png

                  26.tif is now linked to prefix_26,png


                  Or script which can rename selected links to new name and i can than use relink file extension and relink to folder functions.


                  Here is one of kasyan script but need modification. in first box i want to write prefix and that script work on only selected links in links pallete.


                  #target indesign



                  if (app.documents.length == 0) {



                     err("No documents are open. Please open a document and try again.");






                  if (app.activeDocument.links.length == 0) {



                     err("The current document contains no images. Please open a document containing images and try again.");






                  var myFind, myChange, myResult;



                  var myFolder = Folder.selectDialog ("Choose a new job folder");



                  if (myFolder != null) {



                     var myDoc = app.activeDocument;



                     var myLinks = myDoc.links;







                     var myDialog = app.dialogs.add({name:"Change job number", canCancel:true});



                     var myColumn = myDialog.dialogColumns.add();



                     var myPanel = myColumn.borderPanels.add();



                     var myLabel1 = myPanel.staticTexts.add({staticLabel:"Change "});



                     var myText1 = myPanel.textEditboxes.add();



                     if (app.extractLabel("kas_myText1") != "") {



                        myText1.editContents = app.extractLabel("kas_myText1");






                     var myLabel2 = myPanel.staticTexts.add({staticLabel:" to "});



                     var myText2 = myPanel.textEditboxes.add();



                     if (app.extractLabel("kas_myText2") != "") {



                        myText2.editContents = app.extractLabel("kas_myText2");










                     if(myDialog.show() == true){



                        var myFind = myText1.editContents;



                        var myChange = myText2.editContents;







                        app.insertLabel("kas_myText1", myFind);



                        app.insertLabel("kas_myText2", myChange);







                        for (i = myLinks.length-1; i >= 0 ; i--) {



                           var myLink = myLinks[i];



                           var myFile = new File(myLink.filePath);



                           var myNewName = myLink.name.replace(myFind, myChange);



                           var myNewFile = new File(myFolder + "/" + myNewName);



                           if (myFile!= myNewFile) {



                              if (myFile.exists) {










































                  function err(e) {










                  • 6. Re: Relink to new image file by pixel-by-pixel comparison
                    kajzica Level 1

                    this can rename to new name path. script only ask for folder with indd. wont show anything but after you open indd new renamed relinked links appears in links palete. you can customize myFolder toSearch toRelink


                    #target InDesign 


                    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT 



                    var myFolder = '///server/_folder/_folder/'; 

                    var toSearch = ['old1.tif', 'old2.tif']; 

                    var toRelink = ['new1.png', 'new2.png']; 


                    var inddFiles = Folder.selectDialog ('Please choose folder with *.indd-files').getFiles('*.indd'); 

                    var l = inddFiles.length; 


                    if (l === 0){displayDialog('The selcted folder doesn\'t contain ID-Files'); exit()}; 





                    var theDoc = app.activeDocument; 


                    var allLinkNames =theDoc.links.everyItem().name; 


                    for(var i = 0; i < toSearch.length; i++) 

                    var myName = toSearch[i]; 

                    for(var s = 0; s < allLinkNames.length; s++) 

                    var linkName = allLinkNames[s]; 

                    if    (linkName === myName){ 

                    var newFile = File(myFolder + toRelink[i]); 














                    }catch (e){ 

                        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL; 


                        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; 




                    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL; 



                    function displayDialog(aString){   

                    var infoWindow = new Window("palette");    

                    infoWindow.add("statictext", undefined, aString);    




                    • 7. Re: Relink to new image file by pixel-by-pixel comparison
                      Stephen_A_Marsh Adobe Community Professional

                      Can you provide a download link to dropbox or similar (not uploaded to the forum, just in case that changes things), with the same QR code in both formats (say 3 pairs of images to check for consistency in data, zip compressed into one file)? There may be are other ways to check for similarity than just pixel content.


                      On your later post with filename prefix, is the prefix always the same per folder or batch?

                      • 9. Re: Relink to new image file by pixel-by-pixel comparison
                        Stephen_A_Marsh Adobe Community Professional

                        Thanks, I was hoping for a metadata solution, but nothing leaped out at me in your sample files…




                        I’m guessing that you can’t simply batch rename all of your PNG files from:






                        So then you can just relink to the original filename of 1.tif using the built in InDesign feature to relink to the same filename with a different extension.




                        This script does work for your situation, however it is not automated and requires the user to have interaction at key points in each doc and to know a little basic regex/grep: