title: PHP - Script using imagepng won't save file and then display it
body: <p>I'm trying to load an image, edit it, save it and then display it from a script that is called within IMG tags. The script works if I want to just display the image and it does save the image. But it won't save it and then display it. Does anyone know what I'm doing wrong? Any help would be greatly appreciated.</p>
  
  <pre><code>&lt;?php
      header('Content-Type: image/png');
      $file_location = "test.png";
      if (file_exists($file_location)) {
          $img_display = @imagecreatefrompng($file_location);
  
          // This section of code removed as doesn't affect result
  
          imagepng($img_display, $file_location);
          chmod($file_location, 0777);
          imagepng($img_display);
          imagedestroy($img_display);
      }
  ?&gt;
  </code></pre>