[eluser]lefrog[/eluser]
My code is working for resize but for some reason the crop is being ignored.
here's my image functions in my model
Code:
function resize_width($path, $width, $height)
{
// resize the image to a width but maintain the ratio
$rules['image_library'] = 'GD2';
$rules['source_image'] = $path;
$rules['maintain_ratio'] = TRUE;
$rules['master_dim'] = 'width';
$rules['width'] = $width;
$rules['height'] = $height;
$this->load->library('image_lib', $rules);
if ( ! $this->image_lib->resize())
{
die($this->image_lib->display_errors());
}
}
function crop_image($source, $x, $y)
{
$rules['image_library'] = 'GD2';
$rules['source_image'] = $source;
$rules['x_axis'] = $x;
$rules['y_axis'] = $y;
$this->image_lib->clear();
$this->image_lib->initialize($rules);
if ( ! $this->image_lib->crop())
{
die($this->image_lib->display_errors());
}
}
And this is my controller
Code:
function add_staff()
{
$data = array(
'name' => $this->input->post('name'),
'job_title' => $this->input->post('job_title'),
'description' => $this->input->post('details')
);
$this->db->insert('staff', $data);
$last_id = mysql_insert_id();
$file_name = $_FILES['userfile']['name'];
if(!$file_name == "")
{
// set the image path and name file
$update_path = './global_assets/images/staff/';
$img_name = $last_id . ".jpg";
// load the image model
$this->load->model('image');
// call upload image function
$this->image->upload_image($update_path, $img_name);
// resize if required
list($width, $height) = getimagesize($update_path . $img_name);
$file_path = $update_path . $img_name;
if ($width > 113)
{
$this->image->resize_width($file_path, 113, 76);
}
if ($height > 76) {
$this->image->crop_image($file_path, 60, 50);
}
}
redirect("admin/edit_staff_list/");
}
Hope someone can spot something. It's doing me head in.