title: Simple hash of PIL image
body: <h2>Background</h2>
  
  <p>I want to store information of PIL images in a key-value store. For that, I hash the image and use the hash as a key.</p>
  
  <h2>What I tried</h2>
  
  <p>I have been using the following code to compute the hash:</p>
  
  <pre><code>def hash(img):
     return hashlib.md5(img.tobytes()).hexdigest()
  </code></pre>
  
  <p>But it seems like this is not stable. I have not figured out why, but for the same image on different machines, I get different hashes.</p>
  
  <h2>Question</h2>
  
  <p>Is there a simple way of <strong>hashing images that only depends on the image itself</strong> (not on timestamps, system architecture, etc.)?</p>
  
  <p>Note that I do not need similar images to get a similar/same hash, as in <a href="https://stackoverflow.com/questions/998662/what-is-image-hashing-used-for">image hashing</a>. In fact, I want different images to have a different hash, e.g. changing the brightness of the image should change its hash.</p>