Compare bitmap data, pixel data, byte array from renditions between two scene nodes

If I have a document that has 10 scene nodes in it and I want to export all of them to PNGs is there a way to check if the exported images are duplicates of the previous export?

Here’s a snip of what I’m doing:

 application.createRenditions(exportedRenditions);

There’s a few ways that come to mind but they all seem heavy:

  • Export the scene node using createRenditions, read that PNG back in, and store the byte array, export the next scene node, read the PNG back in and compare the two byte arrays and see if they are equal. FYI I don’t know if it’s possible to compare bytearrays but I can’t see why not.
  • Do the same as above but convert to base64 data uri and compare the strings. This is if comparing byte arrays is not possible or slower
  • Or if there is a file object API method that can compare files, if (fileA.same(fileB)).

I don’t know if there is API for this but:

  • Create a rendition in memory (not to disk), get the bitmap data, do the same for the next scene node and then compare the bitmap data. Compare pixel by pixel.

Really hacky heuristics hack idea:

  • Check the export sizes of each exported scene node. If the next scene node is an exact size match of a previous assume that they are same exact export and then handle cases where they are not. I don’t know the failure or success rate of this but with a message to the user to double check the results and give an opt out option.

An alternative option that may be easy addition:

  • In application.createRenditions API check if each scene node bitmap data is the same as what has been exported before and then in the array of rendition objects returned from application.createRenditions mark the duplicates and add a link to the first result that contains the same image data.
var results  =  await application.createRenditions(exportedRenditions);

for (result in results) {
    if (result.duplicate) {
        log(result.duplicateResult); 
    }
}

You could also have a do not export duplicates option on the rendition options passed in as long as there was a way to figure out the duplicates.

1 Like