Welcome Guest, Not a member yet? Register   Sign In
Resizing images and making thumbs
#1

[eluser]mstojanov[/eluser]
Hello guys, i'm trying to resize the image who iam trying to upload and to make a thumb of the image.

What i get in mu uploads folder is my original image {not resized 3.2 mb} and my _thumb image which is really okay.

here is my controller

Code:
class Upload extends CI_Controller {

public function __construct(){
  parent::__construct();
  $this->load->model('oglas_model');
  session_start();
}

function index(){
  $this->load->view('nov_oglas', array('error' => ' ' ));
}

function do_upload(){

  $config['upload_path'] = './uploads';
  $config['allowed_types'] = 'gif|jpg|jpeg|png';
  $config['max_size'] = '4000';
  $config['encrypt_name'] = TRUE;
  $config['max_width']  = '4300';
  $config['max_height']  = '3000';
  $config['remove_spaces']   = TRUE;

  $this->load->library('upload', $config);
  $this->load->library('form_validation');

  $this->form_validation->set_rules('ime','Ime', 'required');
  $this->form_validation->set_rules('email','Email', 'required|valid_email');
  $this->form_validation->set_rules('telefon','Telefon', 'trim|required|max_length[16]');
  $this->form_validation->set_rules('grad','grad', 'required');
  $this->form_validation->set_rules('naslov','Naslov', 'required');
  $this->form_validation->set_rules('opis','Email', 'required');
  $this->form_validation->set_rules('cena','Cena','required|numeric');
    
   if ($this->form_validation->run() !== false){

  if ( ! $this->upload->do_upload()) {
   $error = array('error' => $this->upload->display_errors());

  } else {

   $data = array('upload_data' => $this->upload->data());
   $finfo=$this->upload->data();
   $this->_createThumbnail($finfo['file_name']);
                        $this->resize_image($finfo['file_name']);
   $data['thumbnail_name'] = $finfo['raw_name']. '_thumb' .$finfo['file_ext'];
   $data['uploadInfo'] = $finfo;
   $this->oglas_model->insert_oglas($finfo);
   $this->load->view('upload_success', $data);
  }

}
  $error = array('error' => $this->upload->display_errors());
  $this->load->view('nov_oglas',$error);

}

  function _createThumbnail($filename) {

        $config['image_library']    = "gd2";      
        $config['source_image']     = "uploads/" .$filename;      
        $config['create_thumb']     = TRUE;      
        $config['maintain_ratio']   = TRUE;
        $config['quality'] = "60%";
     $config['width'] = "400";      
        $config['height'] = "400";

        $this->load->library('image_lib',$config);

        if(!$this->image_lib->resize()){
            echo $this->image_lib->display_errors();
         }      

     }

         function resize_image($filename) {

        $config['image_library']    = "gd2";      
        $config['source_image']     = "uploads/" .$filename;      
        $config['maintain_ratio']   = TRUE;
        $config['quality'] = "80%";
     $config['width'] = "1024";      
        $config['height'] = "768";

        $this->load->library('image_lib',$config);

        if(!$this->image_lib->resize()){
            echo $this->image_lib->display_errors();
         }      

     }

}





Theme © iAndrew 2016 - Forum software by © MyBB