resize image with php
<p>hi every one 
 I have script to resize image. It work well except output. In out put it gives binary stream but i want image . my code is following
             

<pre><code>class SimpleImage {

    var $image;
   var $image_type;

 function load($filename) {
    $image_info = getimagesize($filename);
  $this-&gt;image_type = $image_info[2];
  if( $this-&gt;image_type == IMAGETYPE_JPEG ) {
     $this-&gt;image = imagecreatefromjpeg($filename);
  } elseif( $this-&gt;image_type == IMAGETYPE_GIF ) {
     $this-&gt;image = imagecreatefromgif($filename);
  } elseif( $this-&gt;image_type == IMAGETYPE_PNG ) {
     $this-&gt;image = imagecreatefrompng($filename);
  }
  }
   function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
  if( $image_type == IMAGETYPE_JPEG ) {
     imagejpeg($this-&gt;image,$filename,$compression);
  } elseif( $image_type == IMAGETYPE_GIF ) {
     imagegif($this-&gt;image,$filename);         
  } elseif( $image_type == IMAGETYPE_PNG ) {
     imagepng($this-&gt;image,$filename);
  }   
  if( $permissions != null) {
     chmod($filename,$permissions);
  }
  }
  function output($image_type=IMAGETYPE_JPEG) {
  if( $image_type == IMAGETYPE_JPEG ) {
     imagejpeg($this-&gt;image);
  } elseif( $image_type == IMAGETYPE_GIF ) {
     imagegif($this-&gt;image);         
  } elseif( $image_type == IMAGETYPE_PNG ) {
     imagepng($this-&gt;image);
  }  

 }
  function getWidth() {
  return imagesx($this-&gt;image);
   }
   function getHeight() {
  return imagesy($this-&gt;image);
   }
   function resizeToHeight($height) {
  $ratio = $height / $this-&gt;getHeight();
  $width = $this-&gt;getWidth() * $ratio;
  $this-&gt;resize($width,$height);
  }
  function resizeToWidth($width) {
  $ratio = $width / $this-&gt;getWidth();
  $height = $this-&gt;getheight() * $ratio;
  $this-&gt;resize($width,$height);
   }
     function scale($scale) {
  $width = $this-&gt;getWidth() * $scale/100;
  $height = $this-&gt;getheight() * $scale/100; 
  $this-&gt;resize($width,$height);
     }
       function resize($width,$height) {
          $new_image = imagecreatetruecolor($width, $height);
         imagecopyresampled($new_image, $this-&gt;image, 0, 0, 0, 0, $width, $height,$this-&gt;getWidth(), $this-&gt;getHeight());
       $this-&gt;image = $new_image;   
        }      
     }
    ?&gt;
</code></pre>

<p>and</p>

<pre><code>   &lt;?php
         if( isset($_POST['submit']) ) {
          include('SimpleImage.php');
         $image = new SimpleImage();
         $image-&gt;load($_FILES['uploaded_image']['tmp_name']);
              $image-&gt;resizeToWidth(400,400);
          $image-&gt;save($_FILES['uploaded_image']['name']);

         $image-&gt;output();
           } else {
       ?&gt;

      &lt;form action="" method="post" enctype="multipart/form-data"&gt;
       &lt;input type="file" name="uploaded_image" /&gt;
       &lt;input type="submit" name="submit" value="Upload" /&gt;
     &lt;/form&gt;

       &lt;?php
               }
              ?&gt;
</code></pre>
