SImple solution to Codeigniter image class? -


i have messy code, use simpleimage, know can use codeigniter image class, config little big, can post little elegant , better solution, code now, want rid of simpleimage, , image class initialized in controller.here have:

// main config $config['image_library'] = 'gd2'; $config['maintain_ratio'] = true; $config['height'] = '1'; $config['master_dim'] = 'width'; $config['overwrite'] = true;  // resize image simpleimage $novaslika="img/proizvodi/".$last.".jpg"; $image = new simpleimage(); $image->load($_files['slika']['tmp_name']); $image->resizetowidth(800); $image->save($novaslika);  // create png  $config['source_image'] = $_files['maska']['tmp_name']; $config['width']     = 800; $config['new_image']    = "./img/proizvodi/".$last."_maska.png"; $this->image_lib->initialize($config); $this->image_lib->resize();   // create thumb $config['source_image'] = './img/proizvodi/'.$last.'.jpg'; $config['create_thumb'] = true; $config['new_image']    = './img/proizvodi/thumbs/'.$last.'_thumb.jpg'; $this->image_lib->initialize($config); $this->image_lib->resize(); 

you can this:

function index() {     $this->load->library('image_lib');      $a = array(         'source_image' => 'images/1.jpg',         'width' => 100,         'height' => 100,         'new_image' => 'images/2.jpg',         'create_thumb' => true,         'overwrite' => false     );       $image = $this->_image_manipulation($a);      if($image === true)     {         echo "image ok";     }     else     {         echo $image;     }  }  private function _image_manipulation($configs = '') {     if($configs)     {         $config['image_library'] = 'gd2';   //static         $config['maintain_ratio'] = true;   //static         $config['master_dim'] = 'width';    //static          $config['source_image'] = $configs['source_image'];//required          $config['height']       = (isset($configs['height']))?$configs['height']:null;                   $config['width']        = (isset($configs['width']))?$configs['width']:null;          $config['overwrite']    = (isset($configs['overwrite']))?$configs['overwrite']:null;          $config['new_image']    = (isset($configs['new_image']))?$configs['new_image']:null;         $config['create_thumb'] = (isset($configs['create_thumb']))?$configs['create_thumb']:null;          $this->image_lib->initialize($config);          if ( ! $this->image_lib->resize())         {             return $this->image_lib->display_errors();         }         else         {             return true;         }     } } 

but still need simpleimage library convert png's unless, , can't confirm, simpleimage using imagemagick. if is, means it's installed on system , can change

$config['image_library'] = 'gd2'; 

to

$config['image_library'] = 'imagemagick'; 

and codeigniter handle image conversion too; need rename file:

$a = array(     'source_image' => 'images/1.jpg',     'new_image' => 'images/1.png', ); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -