[PHP] 업로드된 이미지 정사각형으로 썸네일 만드는 함수
upload 함수(Controller)
/** * Upload한 이미지를 저장 하고 사이즈가 정사각형인 이미지로 썸네일 만든다. * @param String $upload_file * @param String $target_file * @param String $s */ function img_upload($upload_file, $target_file, $s = 90) { $ret = FALSE; // 이미지 업로드 설정 $config = array( 'upload_path' => 'image/', 'overwrite' => TRUE, 'allowed_types' => 'gif|jpg|png', 'file_name' => $target_file ); $this->load->library('upload', $config); if ($this->upload->do_upload($upload_file)) { list($w, $h) = getimagesize($config['upload_path'] . $target_file); $master_dim = $w > $h ? 'height' : 'width'; $config = array( 'image_library' => 'gd2', 'source_image' => $config['upload_path'] . $target_file, 'new_image' => $config['upload_path'] . 'thumb/' . $target_file, 'master_dim' => $master_dim, 'width' => $s, 'height' => $s ); $this->load->library('image_lib', $config); $this->image_lib->resize(); list($w, $h) = getimagesize($config['new_image']); $config = array( 'image_library' => 'gd2', 'source_image' => $config['new_image'], 'maintain_ratio' => FALSE, 'width' => $s, 'height' => $s, 'y_axis' => round(($h - $s) / 2), 'x_axis' => round(($w - $s) / 2) ); $this->image_lib->clear(); $this->image_lib->initialize($config); $this->image_lib->crop(); $ret = TRUE; } return $ret; } $this->img_upload('upimg', 'test.jpg', 120);