Get new image using image crop library of Codeigniter

629 Views Asked by At

I want to get the file name of new image created using the image crop library in Codeigniter and save it in a mysql database.

This is my current cropping code:

$data['x'] = $this->input->post('x1');
$data['y'] = $this->input->post('y1');
$data['w'] = $this->input->post('width');
$data['h'] = $this->input->post('height');

$config['image_library'] = 'gd2';
$config['source_image'] = 'assets/images/supplier_photos/'.$this->input->post('img_file');
$config['create_thumb'] = TRUE;
$config['new_image'] = './assets/images/supplier_photos/crop/'.$this->input->post('img_file');
$config['maintain_ratio'] = FALSE;
$config['width']  = $data['w'];
$config['height'] = $data['h'];
$config['x_axis'] = $data['x'];
$config['y_axis'] = $data['y'];

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

if(!$this->image_lib->crop())
{
    echo $this->image_lib->display_errors();
}  
$this->suppliers_model->update_photos();

Now I want to get the file name of the new image created. How can I do this?

1

There are 1 best solutions below

0
On

The name of the image is stored in the POST value of img_file. You can access it via $this->input->post('img_file') (in fact your configuration is concatenating that to the path). You can assign this to a variable like this:

$file_name = $this->input->post('img_file');

You can then use $file_name wherever you would like to use the actual file name without the path.