title: Resize images with PHP, support PNG, JPG
body: <p>I am using this class:</p>
  
  <pre><code>class ImgResizer {
  
  function ImgResizer($originalFile = '$newName') {
      $this -&gt; originalFile = $originalFile;
  }
  function resize($newWidth, $targetFile) {
      if (empty($newWidth) || empty($targetFile)) {
          return false;
      }
      $src = imagecreatefromjpeg($this -&gt; originalFile);
      list($width, $height) = getimagesize($this -&gt; originalFile);
      $newHeight = ($height / $width) * $newWidth;
      $tmp = imagecreatetruecolor($newWidth, $newHeight);
      imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
  
      if (file_exists($targetFile)) {
          unlink($targetFile);
      }
      imagejpeg($tmp, $targetFile, 95);
  }
  
  }
  </code></pre>
  
  <p>Which works excellently, but it fails with png's, it creates a resized black image.</p>
  
  <p>Is there a way to tweak this class to support png images?</p>