What I did was, on one hand:
import wand # user-installed
img = wand.image.Image(filename=f)
print(img.signature)
which yields results equivalent to invoking imagemagick in the local shell:
import subprocess # builtins
cmd = f'identify -format \'%#\' {f}'
print(str(subprocess.check_output(cmd, shell=True),'utf-8'))
and, on the other hand:
import hashlib # builtins
sha_256 = hashlib.sha256()
sha_256.update(open(f,'rb').read() )
print(sha_256.hexdigest())
For a given jpg file, f, I get:
bcabffbb94896989099e5d2c11989468567a5f9ca46f12aecc2448079b6c77cb in the first case, and
6964a03b39bd71d8cff04cf075d008a93cd3a4973c95edf1e6cfa8c1f5eeb3e0 in the second case.
I suspect that it is because the second method, with hashlib, may scoop in more to the image file than just its "clean" pixel stream, perhaps some file metadata, etc. wand does not as it relies only on the pixel stream.
I'd like to reproduce the wand result with hashlib for Python 3.9.0, but did not get very far on the documentation. Any pointers anyone?