title: PHP image comparison
body: <p>img_1 is created by PHP and img_2 is saved on server. I'm trying to compare those to images to see if they're different, I tried this but it doesn't work.</p>
  
  <pre><code>$script_img = imagecreatetruecolor(2390, 2400);
  $web_img = imagecreatefrompng("URL_TO_IMG");
  
  if ($script_img==$web_img ) {
      echo "SAME";
  }
  else{
      echo "DIFFERENT";
  }
  </code></pre>
  
  <p>Next example works but when I call <code>imagepng</code> PHP creates image in browser or weird letters (if headers isn't set to image/png) and I don't want that.</p>
  
  <pre><code>$script_img = imagecreatetruecolor(2390, 2400);
  $web_img = imagecreatefrompng("URL_TO_IMG");
  $rendered = imagepng($web_img);
  
  if ($script_img==$rendered ) {
      echo "SAME";
  }
  else{
      echo "DIFFERENT";
  }
  </code></pre>
  
  <p>I also tried <code>file_get_contents($script_img) == file_get_contents("URL_TO_IMG")</code> but it doesn't work.</p>
  
  <p>Using <code>md5(file_get_contents(imagecreatetruecolor(2390, 2400))) == md5(file_get_contents(imagecreatefrompng("URL_TO_IMG")))</code> works but I doubt that is the best/correct way to compare 2 images.</p>
  
  <hr>
  
  <p>What is the best/correct way to compare images in PHP?</p>