title: How to automatically resize uploaded photo in PHP?
body: <p>How to auto resize the image uploaded to this foder: 'assets/media/':</p>
  
  <pre><code>&lt;?php defined('SYSPATH') OR die('No direct access allowed.');
  
  class Uploader_Controller extends Controller_Core {
  
  public function bulkUpload() {
      Kohana::log('debug', 'Start to upload');
      $files = Validation::factory($_FILES)
                      -&gt;add_rules('picture', 'upload::valid', 'upload::required', 'upload::type[gif,jpg,png,jpeg]', 'upload::size[10M]');
      Kohana::log('debug', 'Start to validate');
      if ($files-&gt;validate()) {
          Kohana::log('debug', 'validate passed');
  
          $filename = upload::save('picture');
          $thumbSize = Kohana::config('upload.thumb_size');
  
          Image::factory($filename)
                  -&gt;resize($thumbSize[0], $thumbSize[1], Image::WIDTH)
                  -&gt;save(DOCROOT . 'assets/media/thumbs/' . basename($filename));
  
          $partName = explode('/', $filename);
          $picture = $partName[count($partName) - 1];
          $data['name'] = '';
          $data['picture'] = $picture;
          $data['category_id'] = $this-&gt;input-&gt;post('category_id', 0);
          $data['description'] = '';
          ;
          $data['user_id'] = $this-&gt;input-&gt;post('user_id', 0);
          $pictureModel = new Picture_Model();
          try {
              $photo = $pictureModel-&gt;savePicture($data);
              echo url::site('assets/media/' . $picture);
          } catch (Exception $e) {
  
          }
      }
  }
  }
  </code></pre>
  
  <p>i have add this line but still not working:</p>
  
  <p><code>$filename-&gt;resizeToWidth(300);</code></p>