[eluser]Wonder Woman[/eluser]
Hi,
I have a form which uploads an image and copies it in to three other folders but resizes it before they are put there. However, I need these images to be the exact sizes which I specify without stretching etc, so I have tried the cropping feature but I can't seem to get it right because the image is black when I look at it.
I would be most grateful if you could help me.
Controller
Code:
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/original/';
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
$this->load->library('upload');
$this->upload->initialize($config);
if(!$this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('submit', $error);
}
else {
$data['upload_data'] = array('upload_data' => $this->upload->data());
$file_name = $this->upload->file_name;
list($image_width, $image_height) = getimagesize($_SERVER['DOCUMENT_ROOT'].'/website/uploads/original/'.$file_name);
// create small size
$config['image_library'] = 'GD2';
$config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/original/'.$file_name;
$config['new_image'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name;
$config['maintain_ratio'] = TRUE;
$config['width'] = 181;
$config['height'] = 115;
$config['master_dim'] = 'width';
$this->load->library('image_lib');
$this->image_lib->initialize($config);
if($image_width >= $config['width'] AND $image_height >= $config['height'])
{
if (!$this->image_lib->resize())
{
echo $this->image_lib->display_errors();
} else {
if(file_exists($_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name))
{
list($image_width, $image_height) = getimagesize($_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name);
if($image_height > '115')
{
$config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name;
$y_axis = $image_height - 115;
$config['y_axis'] = $y_axis;
$config['x_axis'] = 181;
$this->image_lib->initialize($config);
if (!$this->image_lib->crop())
{
echo $this->image_lib->display_errors();
} else {
echo "cropped";
}
}
}
}
}
}
If you could tell me where I am going wrong that would be great, I want all images to be 181 by 115.
Many thanks.