I'm having trouble resizing the image and then creating a thumb.
Both functions work separately, but when you try to call both of them, only the first call works. No Thumb Created, Why?
Here is my controller:
if($this->upload->do_upload()){ // Si oui, tout va bien //Update DB $pictureData = $this->upload->data(); if($pictureData['file_name']!=''){ //On resize l'immage //On charge la librarie $this->load->library('thumbs'); $this->thumbs->resize($pictureData['full_path'], 300, 600); $News['image']=$pictureData['file_name']; //On crée un Thumbnail: // on envoi le full path if($this->thumbs->create($pictureData['full_path'])) // on stock le path recu $News['thumb'] = $pictureData['raw_name'].'_thumb'.$pictureData['file_ext']; } }
And here is the library that I created for both functions:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Thumbs { function __construct() { $CI =& get_instance(); $this->load->library('image_lib'); } public function create($picPath) { $CI =& get_instance(); $config['image_library'] = 'gd2'; $config['source_image'] = $picPath; $config['maintain_ratio'] = TRUE; $config['create_thumb'] = TRUE; $config['width'] = 100; $config['height'] = 100; $CI->image_lib->clear(); $CI->image_lib->initialize($config); if(!$CI->image_lib->resize()){ $CI->session->set_flashdata('flashError', $CI->image_lib->display_errors()); return False; } $CI->image_lib->clear(); Return True; } public function resize($picPath, $x, $y) { $CI =& get_instance(); $config1['image_library'] = 'gd2'; $config1['source_image'] = $picPath; $config1['maintain_ratio'] = TRUE; if($x!=0) $config1['width'] = $x; if($y!=0) $config1['height'] = $y; $CI->image_lib->clear(); $CI->image_lib->initialize($config1); if(!$CI->image_lib->resize()){ $CI->session->set_flashdata('flashError', $CI->image_lib->display_errors()); return False; } $CI->image_lib->clear(); Return True; } }
Therefore, if I call only one, it works fine, and it is a function to create or resize. Otherwise, if I try to call them both, only the first function that was called will work.
EDIT: Thanks to fccotech, I did this. here is the solution he came with:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Thumbs { function __construct() { $this->CI =& get_instance(); $this->CI->load->library('image_lib'); } public function create($picPath, $picName) { $config =array(); $config['image_library'] = 'gd2'; $config['source_image'] = $picPath; $config['maintain_ratio'] = TRUE; $config['create_thumb'] = TRUE; $config['width'] = 100; $config['height'] = 100; $config['new_image'] = $picName; // $CI->image_lib->clear(); $this->CI->image_lib->initialize($config); if(!$this->CI->image_lib->resize()){ $this->CI->session->set_flashdata('flashError', $this->CI->image_lib->display_errors()); return False; } $this->CI->image_lib->clear(); Return True; } public function resize($picPath, $x, $y) { $config1 = Array(); $config1['image_library'] = 'gd2'; $config1['source_image'] = $picPath; $config1['maintain_ratio'] = TRUE; if($x!=0) $config1['width'] = $x; if($y!=0) $config1['height'] = $y; // $CI->image_lib->clear(); $this->CI->image_lib->initialize($config1); if(!$this->CI->image_lib->resize()){ $this->CI->session->set_flashdata('flashError', $this->CI->image_lib->display_errors()); $this->CI->image_lib->clear(); return False; } $this->CI->image_lib->clear(); Return True; } }