title: How can I trim white space off image with Intervention?
body: <p>I have a class that takes photos I download before reuploading to S3 for long-term storage and I want to trim the white space.  When I store the temporary image (which works fine), I then try to call the Intervention trim() on it in my storeTempFile() method but that doesn't trim the white space.  I'm thinking it could be the placement in my code?</p>
  
  <pre><code>class PhotoProcessor
  {
    public function __construct(Listing $listing, $photoData)
    {
      $this-&gt;bucket       = 'real-estate-listings';
      $this-&gt;s3           = App::make('aws')-&gt;get('s3');
      $this-&gt;tempFileName = 'app/storage/processing/images/retsphotoupload';
      $this-&gt;photoData    = $photoData;
      $this-&gt;listing      = $listing;
      $this-&gt;photo        = new RetsPhoto;
    }
  
    public function process()
    {
      $this-&gt;storeTempFile();
      $this-&gt;storeFileInfo();
      $this-&gt;buildPhoto();
  
      $success = $this-&gt;pushToS3();
  
      // if Result has the full URL or you want to build it, add it to $this-&gt;photo
      DB::connection()-&gt;disableQueryLog();
      $this-&gt;listing-&gt;photos()-&gt;save($this-&gt;photo);  
      $this-&gt;removeTempFile();
      unset ($this-&gt;photoData);
      return $success;
    }
  
    private function storeTempFile()
    {
      // return File::put($this-&gt;tempFileName, $this-&gt;photoData['Data']) &gt; 0;
      File::put($this-&gt;tempFileName, $this-&gt;photoData['Data']);
      Image::make($this-&gt;tempFileName)-&gt;trim('top-left', null, 60);
      return($this-&gt;tempFileName) &gt; 0;
  
    }
  
    private function storeFileInfo()
    {
      $fileInfo = getimagesize($this-&gt;tempFileName);
      // Could even be its own object
      $this-&gt;fileInfo = [
      'width'     =&gt; $fileInfo[0],
      'height'    =&gt; $fileInfo[1],
      'mimetype'  =&gt; $fileInfo['mime'],
      'extension' =&gt; $this-&gt;getFileExtension($fileInfo['mime'])
      ];
    }
  
    private function buildPhoto()
    {
      $this-&gt;photo-&gt;number = $this-&gt;photoData['Object-ID']; // Storing this because it is relevant order wise
      $this-&gt;photo-&gt;width  = $this-&gt;fileInfo['width'];
      $this-&gt;photo-&gt;height = $this-&gt;fileInfo['height'];
      $this-&gt;photo-&gt;path   = $this-&gt;getFilePath();
    }
  
    private function getFilePath()
    {
      $path   = [];
      if ($this-&gt;listing-&gt;City == NULL)
      {
        $path[] = Str::slug('No City');
      }
      else
      {
        $path[] = Str::slug($this-&gt;listing-&gt;City, $separator = '-'); 
      }
  
      if ($this-&gt;listing-&gt;Subdivision-&gt;subdivision_display_name == NULL)
      {
        $path[] = Str::slug('No Subdivision');
      }
      else
      {
        $path[] = Str::slug($this-&gt;listing-&gt;Subdivision-&gt;subdivision_display_name, $separator = '-');  
      }
  
      if ($this-&gt;listing-&gt;MLSNumber == NULL)
      {
        $path[] = Str::slug('No MLSNumber');
      }
      else
      {
        $path[] = Str::slug($this-&gt;listing-&gt;MLSNumber, $separator = '-');
      }
  
        $path[] = $this-&gt;photoData['Object-ID'].'.'.$this-&gt;fileInfo['extension'];
  
        return strtolower(join('/', $path));
  
    }
  
    private function pushToS3()
    {
      return $this-&gt;s3-&gt;putObject([
        'Bucket'     =&gt; $this-&gt;bucket,
        'Key'        =&gt; $this-&gt;photo-&gt;path,
        'ContentType'=&gt; $this-&gt;fileInfo['mimetype'],
        'SourceFile' =&gt; $this-&gt;tempFileName
      ]);
    }
  
    private function getFileExtension($mime)
    {
      // Use better algorithm than this
      $ext = str_replace('image/', '', $mime);
      return $ext == 'jpeg' ? 'jpg' : $ext;
    }
  
    private function removeTempFile()
    {
      return File::delete($this-&gt;tempFileName);
    }
  }
  </code></pre>