title: compress image file size on upload?
body: <p>I am uploading product screenshots to my website...  I want to upload the original image as it is and also create a thumbnail for it, but after uploading both the files the filesize of the thumbnail created is a bit larger than expected. Is there any way I could reduce the filesize of the thumbnail without compromising much on the quality in php or by using Imagemagick( which I have no idea how to use but I'm willing to learn if needed)...<br>
  Below is the code I'm using to upload my files..<br></p>
  
  <pre><code>&lt;form action="&lt;?php echo $_server['php-self'];  ?&gt;" method="post" enctype="multipart/form-data" id="something" class="uniForm"&gt;
      &lt;input name="new_image" id="new_image" size="30" type="file" class="fileUpload" /&gt;
      &lt;button name="submit" type="submit" class="submitButton"&gt;Upload/Resize Image&lt;/button&gt;
  </code></pre>
  
  <p></p>
  
  <p><br></p>
  
  <pre><code>&lt;?php
      if(isset($_POST['submit'])){
        if (isset ($_FILES['new_image'])){
            $imagename = $_FILES['new_image']['name'];
            $source = $_FILES['new_image']['tmp_name'];
            $target = "images/".$imagename;
            move_uploaded_file($source, $target);
  
            $imagepath = $imagename;
            $save = "images/" . $imagepath; //This is the new file you saving
            $file = "images/" . $imagepath; //This is the original file
  
            list($width, $height) = getimagesize($file) ; 
  
  
            $tn = imagecreatetruecolor($width, $height) ; 
            $image = imagecreatefromjpeg($file) ; 
            imagecopyresampled($tn, $image, 0, 0, 0, 0, $width, $height, $width, $height) ; 
  
            imagejpeg($tn, $save, 100) ; 
  
            $save = "images/sml_" . $imagepath; //This is the new file you saving
            $file = "images/" . $imagepath; //This is the original file
  
            list($width, $height) = getimagesize($file) ; 
  
            $modwidth = 130; 
  
            $diff = $width / $modwidth;
  
            $modheight = 185; 
            $tn = imagecreatetruecolor($modwidth, $modheight) ; 
            $image = imagecreatefromjpeg($file) ; 
            imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
  
            imagejpeg($tn, $save, 100) ; 
          echo "Large image: &lt;img src='images/".$imagepath."'&gt;&lt;br&gt;"; 
          echo "Thumbnail: &lt;img src='images/sml_".$imagepath."'&gt;"; 
  
        }
      } ?&gt;
  </code></pre>
  
  <p>Kindly point me in the right direction...Thanks</p>