Automation/app/Libraries/MyStorage/Mangboard/File/ImageLibrary.php
2024-09-14 18:39:00 +09:00

42 lines
1.5 KiB
PHP

<?php
namespace App\Libraries\MyStorage\Mangboard\File;
use App\Libraries\MyUtil\ImageLibrary as MyUtilLibrary;
class ImageLibrary extends MyUtilLibrary
{
public function __construct() {}
public function create(string $file_name, int $width = 480, int $height = 319): bool|string
{
try {
$file_ext = pathinfo($this->getSourcePath() . DIRECTORY_SEPARATOR . $file_name, PATHINFO_EXTENSION);
if (!$this->isFileType($file_ext)) {
throw new \Exception("{$file_name} Image 형식파일이 아닙니다.");
}
//저장할 디렉토리 생성
$this->makeDirectory($this->getDestinationPath());
// 이미지 파일 로드
$this->load($this->getSourcePath() . DIRECTORY_SEPARATOR . $file_name);
// 200x200으로 이미지 크기 조정
$this->resize($width, $height);
// 파일 저장
$this->save($this->getDestinationPath() . DIRECTORY_SEPARATOR . $this->getDestinationFile());
// 메모리 해제
$this->destroy();
log_message("debug", sprintf(
"%s %s->%s(W:%s,H:%s) 작업완료)",
__FUNCTION__,
$file_name,
$this->getDestinationFile(),
$width,
$height
));
return $file_name;
} catch (\Exception $e) {
log_message("warning", $e->getMessage());
return false;
}
}
}