title: Laravel image intervention compression
body: <p>I have a script which saves and caches images with intervention, and it's working 100%</p>
  
  <p>However i am trying to work out how i can add 75% compression to jpg &amp; png files, but i don't know i would apply it in this situation.</p>
  
  <p>I didn't think PNG files could be compressed apart from software which does it, so im not really sure if its the same thing?</p>
  
  <p>There is an example of compression here: <a href="http://image.intervention.io/api/save" rel="noreferrer">http://image.intervention.io/api/save</a></p>
  
  <pre><code>/* ////////////////////// IMAGES //////////////////////// */
  Route::get( '/media/{size}/{crop}/{name}', function ( $size = null, $crop = null, $name = null ) {
      if ( ! is_null( $size ) and ! is_null( $name ) and ! is_null( $crop ) ) {
          $size = explode( 'x', $size );
  
          $hours = 48;
          $cache_length = $hours * 60;
  
          switch ( $crop ) {
  
              /*///////////////////////// no crop and change ratio */
              case "0":
                  $cache_image = Image::cache( function ( $image ) use ( $size, $name ) {
                      return $image-&gt;make( url( '/uploads/' . $name ) )-&gt;resize( $size[0], $size[1] )-&gt;sharpen(5);
                  }, $cache_length);
                  break;
  
              /*///////////////////////// crop - NO upsize */
              default:
              case "1":
                  $cache_image = Image::cache( function ( $image ) use ( $size, $name ) {
                      return $image-&gt;make( url( '/uploads/' . $name ) )-&gt;fit( $size[0], $size[1], function ( $constraint ) {
                          $constraint-&gt;upsize();
                      } )-&gt;sharpen(5);
                  }, $cache_length );
                  break;
  
              /*///////////////////////// crop - WITH upsize */
              case "2":
                  $cache_image = Image::cache( function ( $image ) use ( $size, $name ) {
                      return $image-&gt;make( url( '/uploads/' . $name ) )-&gt;fit( $size[0], $size[1], function ( $constraint ) {
                          //$constraint-&gt;upsize();
                      } )-&gt;sharpen(5);
                  }, $cache_length );
                  break;
  
              /*///////////////////////// No crop &amp; add borders */
              case "3":
  
                  $cache_image = Image::cache( function ( $image ) use ( $size, $name ) {
  
                      $image-&gt;make( url( '/uploads/' . $name ) )-&gt;resize( $size[0], $size[1], function ( $constraint ) {
                          $constraint-&gt;aspectRatio();
                          $constraint-&gt;upsize();
                      } )-&gt;sharpen(5);
  
                      $image-&gt;resizeCanvas($size[0], $size[1], 'center', false, array(255, 255, 255, 0.0));
  
                      return $image;
  
                  }, $cache_length );
                  break;
  
              /*///////////////////////// No crop */
              case "4":
                  $cache_image = Image::cache( function ( $image ) use ( $size, $name ) {
  
                      $image-&gt;make( url( '/uploads/' . $name ) )-&gt;resize( $size[0], $size[1], function ( $constraint ) {
                          $constraint-&gt;aspectRatio();
                          $constraint-&gt;upsize();
                      } )-&gt;sharpen(5);
  
                      //$image-&gt;resizeCanvas($size[0], $size[1], 'center', false, array(255, 255, 255, 0.0));
  
                      return $image;
  
                  }, $cache_length );
                  break;
  
          }
  
          return Response::make( $cache_image, 200, [ 'Content-Type' =&gt; 'image' ] )-&gt;setMaxAge(604800)-&gt;setPublic();
  
      } else {
          abort( 404 );
      }
  } );
  </code></pre>