Skip to main content
Known Participant
September 11, 2021
Question

How to tell if layers are the same??

  • September 11, 2021
  • 2 replies
  • 483 views

Hi~

Is there a way with jsx scripts to tell if two layers are the same?? So i can just choose one layer to convert to png for saving time。 

I have read the script guiding and did not find a clue.

 

Thanks,my best regard.

 

This topic has been closed for replies.

2 replies

Stephen Marsh
Community Expert
Community Expert
September 11, 2021

This could be done with an action using difference blend mode + equalize, however, as JJMack wrote that depends on both layers having exactly the same alignment. From a scripting perspective, comparing the histogram of each layer in various forms would not have the same limitation.

 

Just curious, why do you have this problem in the first place?

 

hui5C21Author
Known Participant
September 13, 2021

when the art staff finish a UI work with photoshop, I need to export the geometry data, and png of every layer of psd file, and then pack the pngs with texturepacker, and finally reform the UI in my applicaction. As now  i export every layer as png no matter if some of them are the same.

Before pack the pngs i will filter some pngs which are duplicate, i made a md5 value of each png data and compare the value to tell if pngs are the same. But some how i found there would be a little diffirence(mybe two or three pixels is not the same)between two pngs which should be the same ,because one are copied from the other. And some layers are duplicated but then rotated or scaled, In this case I do not know how to to figure out the sittuation. So I wonder if there is an efficient and accurate way to do this work in photoshop.

Kukurykus
Legend
September 11, 2021
activeDocument.histogram

Try above code on only 1st visible layer, to do the same on another.

Make a loop over their histograms to compare values of their cells.

hui5C21Author
Known Participant
September 11, 2021

Compare every pixels?

Legend
September 11, 2021

A histogram is an array of 256 values, each of which describes the number of pixels in an image at a specific brightness level.