How to automatically resize uploaded photo in PHP? -
how auto resize image uploaded foder: 'assets/media/':
<?php defined('syspath') or die('no direct access allowed.'); class uploader_controller extends controller_core { public function bulkupload() { kohana::log('debug', 'start upload'); $files = validation::factory($_files) ->add_rules('picture', 'upload::valid', 'upload::required', 'upload::type[gif,jpg,png,jpeg]', 'upload::size[10m]'); kohana::log('debug', 'start validate'); if ($files->validate()) { kohana::log('debug', 'validate passed'); $filename = upload::save('picture'); $thumbsize = kohana::config('upload.thumb_size'); image::factory($filename) ->resize($thumbsize[0], $thumbsize[1], image::width) ->save(docroot . 'assets/media/thumbs/' . basename($filename)); $partname = explode('/', $filename); $picture = $partname[count($partname) - 1]; $data['name'] = ''; $data['picture'] = $picture; $data['category_id'] = $this->input->post('category_id', 0); $data['description'] = ''; ; $data['user_id'] = $this->input->post('user_id', 0); $picturemodel = new picture_model(); try { $photo = $picturemodel->savepicture($data); echo url::site('assets/media/' . $picture); } catch (exception $e) { } } } } i have add line still not working:
$filename->resizetowidth(300);
you not using kohana image , upload library properly. docs have examples on how use kohana image upload , resize library:
you can resize , save image following code:
image::factory($filename) ->resize(300, null, image::auto) ->save($your_save_path);
Comments
Post a Comment