Created
September 10, 2013 07:39
-
-
Save neamtua/6506153 to your computer and use it in GitHub Desktop.
CI: image resize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _resize($a,$target_width=600,$target_height=600,$marker='thumb_') { | |
$this->load->library('image_lib'); | |
$ret = array('poza'=>'','error'=>''); | |
$size = getimagesize('./uploads/'.$a['file_name']); | |
$a['image_width'] = $size[0]; | |
$a['image_height'] = $size[1]; | |
if ($a['image_width'] > $target_width || $a['image_height'] > $target_height) | |
{ | |
if ($a['image_width'] > $target_width && $a['image_height'] > $target_height) | |
$master_dim = 'auto'; | |
elseif ($a['image_width'] > $target_width) | |
$master_dim = 'width'; | |
else | |
$master_dim = 'height'; | |
$config2['image_library'] = 'gd2'; | |
$config2['source_image'] = FCPATH . '/uploads/'.$a['file_name']; | |
$config2['create_thumb'] = TRUE; | |
$config2['maintain_ratio'] = TRUE; | |
$config2['width'] = $target_width; | |
$config2['height'] = $target_height; | |
$config2['master_dim'] = $master_dim; | |
$config2['new_image'] = FCPATH . '/uploads/'.$marker.$a['file_name']; | |
$config2['thumb_marker'] = ''; | |
$this->image_lib->initialize($config2); | |
if ( ! $this->image_lib->resize()) | |
$ret['error'] = '<div class="error">'.$this->image_lib->display_errors().'</div>'; | |
else $ret['poza'] = $a['file_name']; | |
} | |
else $ret['poza'] = $a['file_name']; | |
return $ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment