title: PHP: Resize image
body: <p>I saw this script on a site, and tried to get it working with my code.
  But when i upload the image i get nothing echo'ed out, and my image is not resized.
  I hope someone could see what im doing wrong.</p>
  
  <p><strong>class.imageResizer.php</strong></p>
  
  <pre><code>&lt;?php
  class ImgResizer {
  var $originalFile = '$newName';
  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);
  }
  }
  ?&gt;
  </code></pre>
  
  <p><strong>The uploader</strong></p>
  
  <pre><code>//If no errors do this
  if (isset($_POST['Submit']) &amp;&amp; !$errors)
  {
      //Resizing the picture
      include 'class.imageResizer.php';
  
      $work = new ImgResizer('users/$username/$imageName');
      $work -&gt; resize(400, 'users/$username/$username-246.$extension');
  
      $sql = "UPDATE members SET user_pic='http://www.something.net/$newName' WHERE username='$username'";
      $_SESSION['user_pic'] = $newName;
      $result = mysql_query($sql);
  mysql_close($conn);
  }
  </code></pre>
  
  <p>The $newName = users/theusername/theusername.theextension</p>
  
  <p>The $imageName = theusername.theextension</p>