Hi;
Can you please help me with this script?
These are my resize criteria. My main concern is number 3
1 - Width smaller that 1063, height smaller than 650. Don’t resize
2 - One dimension bigger (width over 1063 OR height over 650). Don’t resize.
3 - Both bigger (width over 1063 AND height over 650), resize to the smaller of the 2
PHP Code:
private function uploadFile($inputFile="file", $allowed_type="gif|jpg|png", $resize_image = TRUE)
{
//Codeigniter upload
$config['upload_path'] = $this->upload_path;
$config['allowed_types'] = $allowed_type;
$config['encrypt_name'] = TRUE;
$config['max_size'] = $this->maxSize;
$config['max_width'] = 0;
$config['max_height'] = 0;
$this->upload->initialize($config);
if (!$this->upload->do_upload($inputFile))
{
return false;
}
else
{
if($resize_image)
{
$config2['source_image'] = $this->upload->upload_path . $this->upload->file_name;
$size = getimagesize($config2['source_image']);
if($size[0] < 1063 && $size[1] < 650)
{
$config2['width'] = $size[0];
$config2['height'] = $size[1];
}
elseif( ($size[0] < 1063 && $size[1] > 650) || ($size[0] > 1063 && $size[1] < 650))
{
$config2['width'] = $size[0];
$config2['height'] = $size[1];
}
elseif($size[0] > 1063 && $size[1] > 650)
{
$width_diff=(($size[0]*100)/1063);
$height_diff=(($size[1]*100)/650);
if($height_diff<$width_diff)
{
$config2['height'] = 650;
}
else
{
$config2['width'] = 1063;
}
}
$config2['new_image'] = $this->upload->upload_path . $this->upload->file_name;
$config2['image_library'] = 'gd2';
$config2['quality'] = "100%";
$config2['maintain_ratio'] = TRUE;
$this->load->library('image_lib', $config2);
if (!$this->image_lib->resize())
{
//echo $this->image_lib->display_errors();
}
else
{
//echo "Resized successfully!";
}
return $this->upload->data();
}
}
}
Thanks