I am working on media library for a website at the moment, and one of the features is that user can create a cropped version of an image that they upload.
My problem however is this, when I try and crop the image, I get the following error,
The path to the image is not correct.
Here is my code,
$config['image_library'] = 'gd2';
$config['source_image'] = "/media/images/products/".$this->data['image'];
//die($config['source_image']);
$config['maintain_ratio'] = FALSE;
$config['x_axis'] = $this->input->post('x');
$config['y_axis'] = $this->input->post('y');
$config['width'] = $this->input->post('w');
$config['height'] = $this->input->post('h');
$config['dynamic_output'] = FALSE;
$config['create_thumb'] = TRUE;
$this->load->library('image_lib', $config);
if(!$this->image_lib->crop()) {
if($this->input->post('isAjax') == "1") {
echo json_encode($this->image_lib->display_errors());
} else {
$this->data['image_error'] = $this->image_lib->display_errors();
$this->template->build('/admin/media/crop', $this->data);
}
} else {
$filename = base_url()."media/images/products/".$this->data['image'];
$extension_pos = strrpos($filename, '.'); // find position of the last dot, so where the extension starts
$thumb = substr($filename, 0, $extension_pos) . '_thumb' . substr($filename, $extension_pos);
if($this->input->post('isAjax') == 1) {
echo json_encode($success = array('message' => 'Image Cropped'));
} else {
$this->data['success'] = "Image Cropped";
$this->template->build('/admin/media/crop', $this->data);
}
}
So I though I would change $config['source_image']
to the following,
$config['source_image'] = "./media/images/products/".$this->data['image'];
however that just leaves with this message,
Your server does not support the GD function required to process this type of image.
Am I doing something fundamentally wrong? I am only trying to crop a simple .png, and the file certainly exists on my server, and I most definatly have GD2 installed.