[eluser]Unknown[/eluser]
Using the following code, thumbnail is made correctly SOMETIMES and sometimes it is a replica in size as the regular image. Regular image is distorted sometimes depending on the image (if it distorts for an image, it will always distort for that image, and vice-versa).
EDIT: I tried to attach the file, but it is not uploading. Here is link to result image:
Distorted Image
Code:
//incoming variables
$image = $_FILES['newImage'];
$city = $this->input->post('city');
//save big file
$config['image_library'] = 'gd2';
$config['source_image'] = $image['tmp_name'];
$config['maintain_ratio'] = TRUE;
$config['width'] = 150;
$config['height'] = 115;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->coho_model->save_image($image['tmp_name'], self::PATH.$image['name']);
//save thumbnail file
$config['image_library'] = 'gd2';
$config['source_image'] = $image['tmp_name'];
$config['maintain_ratio'] = FALSE;
$config['width'] = 30;
$config['height'] = 20;
$this->load->library('image_lib', $config, 'thumb_lib');
$this->thumb_lib->resize();
$name = explode(".",$image['name']);
$ext = array_pop($name);
$thumbname = implode(".",$name)."_thumb.".$ext;
$this->coho_model->save_image($image['tmp_name'], self::PATH.$thumbname);
//save record
$this->coho_model->set_city_images($city, $image['name'], $thumbname);
$this->coho_model->update_active_city($city, $image['name'], $thumbname);
Distorted Image