title: show resized image on browser without saving it on server
body: <p>I use a super simple image resize php script, which I have integrated on one of my sites based on wordpress. I allow people to resize their image one-by-one, and basically after the resize is done I display it to them in the browser so they could download/save. Here goes the html part.</p>
  
  <pre><code>    &lt;form action="http://awesomeness.com/wp-content/themes/awesome/resize/processupload.php" method="post" enctype="multipart/form-data" id="UploadForm"&gt;
      &lt;input name="ImageFile" type="file" /&gt;
      &lt;input type="submit"  id="SubmitButton" value="Upload" /&gt;
      &lt;/form&gt;
      &lt;div id="output"&gt;&lt;/div&gt;
  </code></pre>
  
  <hr>
  
  <p>There is also a little jquery script that I think is pointless to show here. Its only function is put the resized image into the <code>output-div</code> below the form. Below goes the contents of the mentioned processupload.php.</p>
  
  <pre><code>if(isset($_POST)) {
          $BigImageMaxSize        = 800; 
          $DestinationDirectory   = 'uploads/'; 
          $Quality                = 90;
  
      if(!isset($_FILES['ImageFile']) || !is_uploaded_file($_FILES['ImageFile']['tmp_name'])) {
              die('Something went wrong with Upload!'); 
      }
  
      $RandomNumber   = uniqid(); 
      $ImageName      = str_replace(' ','-',strtolower($_FILES['ImageFile']['name'])); 
      $ImageSize      = $_FILES['ImageFile']['size']; 
      $TempSrc        = $_FILES['ImageFile']['tmp_name']; 
      $ImageType      = $_FILES['ImageFile']['type']; 
  
      switch(strtolower($ImageType))
      {
          case 'image/png':
              $CreatedImage =  imagecreatefrompng($_FILES['ImageFile']['tmp_name']);
              break;
          case 'image/gif':
              $CreatedImage =  imagecreatefromgif($_FILES['ImageFile']['tmp_name']);
              break;          
          case 'image/jpeg':
          case 'image/pjpeg':
              $CreatedImage = imagecreatefromjpeg($_FILES['ImageFile']['tmp_name']);
              break;
          default:
              die('Unsupported File!'); //output error and exit
      }
  
      list($CurWidth,$CurHeight)=getimagesize($TempSrc);
      $ImageExt = substr($ImageName, strrpos($ImageName, '.'));
      $ImageExt = str_replace('.','',$ImageExt);
      $ImageName      = preg_replace("/\\.[^.\\s]{3,4}$/", "", $ImageName); 
      $NewImageName = $ImageName.'-'.$RandomNumber.'.'.$ImageExt;
      $DestRandImageName  = $DestinationDirectory.$NewImageName; 
  
      if(resize_Image($CurWidth,$CurHeight,$BigImageMaxSize,$DestRandImageName,$CreatedImage,$Quality,$ImageType)) {
  
          echo '&lt;div id="output"&gt;';
          echo '&lt;img src="http://awesomewebsite.com/uploads/'.$NewImageName.'" alt="Resized"&gt;';
          echo '&lt;/div&gt;';
  
      } else {
          die('Resize Error'); //output error
      }
  }
  
      function resize_Image($CurWidth,$CurHeight,$MaxSize,$DestFolder,$SrcImage,$Quality,$ImageType) {
      if($CurWidth &lt;= 0 || $CurHeight &lt;= 0) {
          return false;
      }
  
      $ImageScale         = min($MaxSize/$CurWidth, $MaxSize/$CurHeight); 
      $NewWidth           = ceil($ImageScale*$CurWidth);
      $NewHeight          = ceil($ImageScale*$CurHeight);
      $NewCanves          = imagecreatetruecolor($NewWidth, $NewHeight);
  
      if(imagecopyresampled($NewCanves, $SrcImage,0, 0, 0, 0, $NewWidth, $NewHeight, $CurWidth, $CurHeight))
      {
          switch(strtolower($ImageType))
          {
              case 'image/png':
                  imagepng($NewCanves,$DestFolder);
                  break;
              case 'image/gif':
                  imagegif($NewCanves,$DestFolder);
                  break;          
              case 'image/jpeg':
              case 'image/pjpeg':
                  imagejpeg($NewCanves,$DestFolder,$Quality);
                  break;
              default:
                  return false;
          }
      //delete original image and free some memory    
      if(is_resource($NewCanves)) {imagedestroy($NewCanves);} 
      return true;
      }
      }
  </code></pre>
  
  <p>You can see that the original image is deleted automatically by the script once the resize takes place. But I need the resized image deleted from my <code>/uploads</code> folder too. Basically I just want the script to resize the image and display the resized image on the browser itself only, not to save it on server anywhere. Is it possible. If it is could you please suggest me the edits or edit the code in question itself.Credit for <a href="http://www.saaraan.com/2012/05/ajax-image-upload-and-resize-with-jquery-and-php" rel="nofollow noreferrer">original script</a>.  </p>
  
  <blockquote>
    <p>Bottomline of the question would be : How can this script display the
    resized image on the visitor's browser without saving any file (
    original or resized ) anywhere on server.</p>
  </blockquote>
  
  <p><strong>THINGS TRIED</strong> : I am still trying to decipher this <a href="https://stackoverflow.com/questions/15319944/resize-image-and-display-without-saving-it">somewhat similar thread</a> but still am clueless. I am going to keep updating this space until this thing is over. I am trying <a href="http://php.net/manual/en/function.unlink.php" rel="nofollow noreferrer">unlink() method</a> now but I am unable to find the variable to unlink, is it <code>$DestRandImageName</code> ? coz <code>unlink($DestRandImageName)</code> that does not seem to work.</p>
  
  <p><strong>FINAL UPDATE</strong> : After countless minor efforts I finally got it done. I dont think I should add it as answer so, here. I got all my solutions in <a href="http://www.geekality.net/2011/05/01/php-how-to-proportionally-resize-an-uploaded-image/" rel="nofollow noreferrer">this tutorial</a>. Discovered that if I only need to reproduce the image to the browser without saving it, I will need to take a different approach employing php functions like <a href="http://php.net/manual/en/function.imagecopyresampled.php" rel="nofollow noreferrer">imagecopyresampled()</a> and <a href="http://php.net/manual/en/function.imagejpeg.php" rel="nofollow noreferrer">imagejpeg()</a>. Learned it the hard way, but glad.</p>