CI 코드
| 불의회상 | |
|---|---|
|
업로드된 이미지를 정사각형으로 잘라 썸네일을 만들어 주는 함수 입니다. 이미지 업로드시 관련 컨트롤러에 함수 만들어 넣으시고 호출하여 주시면 됩니다. Html( View) <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body> <form action="upload" method="post" enctype="multipart/form-data"> <table> <tr> <td>upimg</td> <td><input type="file" name="upimg" value="" /></td> </tr> <tr> <td colspan="2"><input type="submit" /></td> </tr> </table> </form> </body> </html>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);
|
|
| 번호 | 제 목 | 글쓴이 | 날짜 | 조회 | 추천수 |
|---|---|---|---|---|---|
| 580 | CodeIgniter SimpleXML library [2] | 타로 | 2012-02-05 | 224 | 0 |
| 577 | CI 와 Smarty 템플릿의 결합 [2] | 불의회상 | 2012-01-26 | 284 | 0 |
| 573 | Okada Design Blog 소개 [3] | 타로 | 2012-01-12 | 384 | 0 |
| 568 | woctopus 계정관리도구 [2] | milosz | 2012-01-09 | 305 | 0 |
| 566 | 업로드된 이미지 정사각형으로 썸네일 만드는 함수 [3] | 불의회상 | 2012-01-06 | 311 | 0 |
| 554 | 코드 이그나이터를 접하고 처음으로 만들어본 객체 입.. [6] | 내일은 | 2011-11-11 | 1375 | 0 |
| 528 | 모델코드 생성기 [25] | 불의회상 | 2011-10-13 | 1224 | 1 |
| 525 | ci memo + tank_auth [2] | milosz | 2011-10-04 | 1044 | 0 |
| 512 | 포럼소스를 2.0.1 버전에 맞게 수정하였습니다. [2] | 탱크 | 2011-04-02 | 3635 | 2 |
| 509 | CI 메뉴얼 CHM 버전(영문 2.0) [1] | 브라이언 | 2011-03-30 | 1288 | 0 |
| 508 | CI 메뉴얼 CHM 버전 [0] | 브라이언 | 2011-03-30 | 1434 | 0 |
| 494 | ci memo [8] | pam | 2011-02-20 | 2021 | 1 |
| 489 | CI 압축 프로그램 [2] | 준이 | 2010-12-27 | 1713 | 0 |
| 482 | 듬직이님의 헬퍼 ip 부분 추가. [0] | 나이유미 | 2010-11-22 | 2062 | 0 |
| 475 | SELECT() 사용 시 문제점 [2] | 마냐 | 2010-09-16 | 2821 | 0 |
| 473 | CI의 사용자 인증 소스파일 [2] | corean | 2010-09-12 | 3252 | 0 |
| 471 | CI 1.7.2 한글 언어팩 1.1 [1] | cleansugar | 2010-08-26 | 2257 | 0 |
| 470 | Upload 라이브러리 수정본 [0] | sisco | 2010-07-28 | 2450 | 0 |
| 464 | iScaffold [4] | 준이 | 2010-07-26 | 2036 | 0 |
| 458 | 이미지 등분하기_helper [0] | 마냐 | 2010-06-18 | 2266 | 0 |

