Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Compare every pixels?
Copy link to clipboard
Copied
A histogram is an array of 256 values, each of which describes the number of pixels in an image at a specific brightness level.
Copy link to clipboard
Copied
If I duplicate normals pixels layer and change the duplicate layer blend mode to difference you will see Black. The layer are the same. Now if I shift one of the layers 1 pixels. The layers are not aligned and I do not see all black. While the layer have identical pixel content and will have the same histogram they have a different alignment they have different background boarded. Their layer bound are different The miss alignment can be great the histogram will still be the same. The content location is not the same.
Copy link to clipboard
Copied
No, just histogram cells values of both layers.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.