Thumbnail 특정 경로에 저장된 원본 이미지의 썸네일을 생성하여 저장하는 방법을 안내합니다.
사용 준비
Thumbnail을 사용하기 위해선 아래와 같이 Controller 최상단에 use 가 선언 되어야 합니다.
Controller
/app/test.php
Thumbnail을 수행하기 위해 새로운 인스턴스를 생성합니다.
<?php use Make\Library\Imgresize;
Controller
/app/test.php
<?php use Make\Library\Imgresize; ... $thumbnail = new Imgresize();
Thumbnail 설정
아래 예시와 같이 특정 경로에 저장된 원본 이미지를 복사하여 원하는 사이즈 및 화질로 리사이징하여 썸네일 이미지로 저장할 수 있습니다.
Controller
/app/test.php
<?php
use Make\Library\Imgresize;
...
$thumbnail = new Imgresize();
$org_file = PH_DATA_PATH.'/img.jpg';
$new_file = PH_DATA_PATH.'/img_thumbnail.jpg';
$thumbnail->set(
array(
'orgimg' => $org_file,
'newimg' => $new_file,
'width' => 800,
'quality' => 70
)
);
| Option | 설명 | 기본값 |
|---|---|---|
| orgimg | 원본 이미지 경로 | |
| newimg | 썸네일이 저장될 이미지 경로 | |
| width | 리사이징할 최대 사이즈 | |
| quality (Optional) | 리사이징할 이미지 화질 | 80 |
Thumbnail 생성 수행
make() 로 썸네일 생성을 수행합니다.
Controller
/app/test.php
<?php
use Make\Library\Imgresize;
...
$thumbnail = new Imgresize();
$org_file = PH_DATA_PATH.'/img.jpg';
$new_file = PH_DATA_PATH.'/img_thumbnail.jpg';
$thumbnail->set(
array(
'orgimg' => $org_file,
'newimg' => $new_file,
'width' => 800,
'quality' => 70
)
);
$thumbnail->make();
연관 가이드 바로가기
서버에 파일 업로드 방법 안내
