Codeigniter image resize?
I have problem with image class in CI?
This is example
On controller:
$this->load->library( array('image_lib') );
On view i have this:
foreach($results as $row)
{
$config['image_library'] = 'gd2';
$config['source_image'] = '/img/proizvodi/'.$row->proizvodid.'.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
But i got no error, and thumb image is not created? I dont know where is mistake?
You shouldn't load image_lib in foreach. Try to use code below
$this->load->library('image_lib');
foreach($results as $row) {
$config['image_library'] = 'gd2';
$config['source_image'] = '/img/proizvodi/'.$row->proizvodid.'.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
}
If it wont work - check the upload folder permissions.
function uploadimage()
{
$file_name = $this->input->post('fileName');
$imageName = 'set_'.file_name($_FILES["file"]['name'],date('Ymd_his'));
$config['image_library'] = 'gd2';
$config['source_image'] = $imageName;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['master_dim'] = 'width';
upload_resize('file','settings', $imageName );
$config['width'] = 200;
$config['height'] = 62;
$this->load->library('image_lib', $config);
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
$json_data = array(
'error' =>false,
'tmp_name' =>$file_name,
'file_name' =>base_url().'assets/uploads/settings/'.$imageName.'?dummy='.rand(0,1000),
'file_path' =>$imageName
);
echo json_encode($json_data);
}
}
this code upload image to folder before save to table.
$config['upload_path'] = './berkas/content/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 0;
$config['max_width'] = 1024000;
$config['max_height'] = 7680000;
$config['encrypt_name'] = TRUE;
$config['overwrite'] = FALSE;
$this->load->library('upload', $config);
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];
$params['gambar'] = $file_name;
$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = './berkas/content/'.$file_name;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 550;
$config['height'] = 350;
$params = array('gambar' => $file_name);