title: How to compress image before uploading in Laravel?
body: <p>I'm making a images gallery website where users can upload any image and they will be displayed on frontend. I need to compress images without effecting it's quality to reduce there size so that page load speed should not effect that much. I'm using following code to upload image:</p>
  
  <pre><code>$rules = array('file' =&gt; 'required');
  $destinationPath = 'assets/images/pages'
  $validator = Validator::make(array('file' =&gt; $file), $rules);
  if ($validator-&gt;passes()) {
     $filename = time() . $uploadcount . '.' . $file-&gt;getClientOriginalExtension();
     $file-&gt;move($destinationPath, $filename);
     return $filename;
  } else {
     return '';
  }
  </code></pre>