파일업로드 추가
Some checks failed
Close Pull Request / main (pull_request_target) Has been cancelled

This commit is contained in:
yangsh
2026-01-28 16:09:52 +09:00
parent b51f2fddcf
commit d134b27614
5 changed files with 1330 additions and 257 deletions

View File

@@ -38,11 +38,7 @@ class Common
*/
public function watermarking($imagePath, $watermark_info, $wmText, $cpid, $key = '')
{
$CI =& get_instance();
$CI->load->library('upload');
$uploader = new MyUpload();
$wmImagePath = ''; // 워터마크 이미지의 경로
$wmSpaceHeihgt = 0; // 워터마크 이미지 하단 공백
@@ -54,9 +50,31 @@ class Common
try {
// $img = new Imagick($imagePath);
$img = new \Imagick();
$img->readImageBlob($imagePath);
if (is_string($imagePath) && is_file($imagePath)) {
$img->readImage($imagePath);
} elseif (is_string($imagePath) && filter_var($imagePath, FILTER_VALIDATE_URL)) {
$headers = @get_headers($imagePath, 1) ?: [];
$blob = @file_get_contents($imagePath);
$contentType = '';
if (!empty($headers)) {
$contentType = is_array($headers['Content-Type'] ?? null)
? end($headers['Content-Type'])
: ($headers['Content-Type'] ?? '');
}
log_message('info', '[watermarking] source url={url} status={status} content_type={ctype} size={size}', [
'url' => $imagePath,
'status' => is_array($headers) && isset($headers[0]) ? $headers[0] : '(no status)',
'ctype' => $contentType,
'size' => $blob === false ? 0 : strlen($blob),
]);
if ($blob === false) {
throw new \RuntimeException('Failed to load image from URL');
}
$img->readImageBlob($blob);
} else {
$img->readImageBlob($imagePath);
}
$hImg = $img->getImageHeight();
$wImg = $img->getImageWidth();
@@ -90,7 +108,7 @@ class Common
$wm = new Imagick(FCPATH . $wmImagePath);
$wm = new \Imagick($wmImagePath);
$hWm = $wm->getImageHeight();
$wWm = $wm->getImageWidth();
@@ -98,22 +116,25 @@ class Common
$wmImgTop = floor(($hImg - $hWm - $wmSpaceHeihgt - $wmTextHeight) / 2); // 워터마크 이미지의 위치 top
$wmTxtTop = $wmImgTop + $hWm + $wmSpaceHeihgt + ($wmTextHeight * 0.6); // 워터마크 텍스트의 위치
$img->compositeImage($wm, imagick::COMPOSITE_OVER, $wmImgLeft, $wmImgTop, imagick::ALIGN_CENTER);
$img->compositeImage($wm, \Imagick::COMPOSITE_OVER, $wmImgLeft, $wmImgTop);
$wm->destroy();
$draw = new \ImagickDraw();
$wmFont = BASEPATH . 'fonts/' . $wmFont;
$draw->setFont($wmFont);
$basePath = defined('BASEPATH') ? BASEPATH : (defined('ROOTPATH') ? ROOTPATH . 'system/' : '');
$wmFont = $basePath . 'fonts/' . $wmFont;
if (is_file($wmFont)) {
$draw->setFont($wmFont);
}
$draw->setFontSize($wmFontSize);
$draw->setFillColor(new ImagickPixel($wmTextColor));
$draw->setFillColor(new \ImagickPixel($wmTextColor));
// $draw->setFillAlpha( $wmTextAlpha );
$draw->setFillOpacity($wmTextAlpha); // 워터마크 텍스트 투명도 설정
$draw->setTextAlignment(2); // center
$draw->setStrokeAntialias(1);
$draw->setStrokeWidth(1);
$draw->setStrokeColor(new ImagickPixel('#000000'));
$draw->setStrokeColor(new \ImagickPixel('#000000'));
// $draw->setStrokeAlpha(0.1);
$draw->setStrokeOpacity(0.1);
$draw->annotation($wImg / 2, $wmTxtTop, $wmText);
@@ -125,12 +146,27 @@ class Common
$watermark_img = $img->getImageBlob();
$CI->upload->upload_object_storage_imagick($key, $watermark_img);
if (empty($key)) {
throw new \RuntimeException('Empty upload key');
}
$ok = $uploader->upload_object_storage_imagick2($key, $watermark_img);
if ($ok) {
log_message('info', '[watermarking] upload success key={key} size={size} cpid={cpid}', [
'key' => $key,
'size' => strlen($watermark_img),
'cpid' => $cpid,
]);
} else {
log_message('error', '[watermarking] upload failed key={key} cpid={cpid}', [
'key' => $key,
'cpid' => $cpid,
]);
}
$img->destroy();
// $object_upload = $this->upload->upload_object_storage($imagePath , $imagePath , 'data');
} catch (Exception $e) {
echo $e->getMessage();
} catch (\Throwable $e) {
log_message('error', '[watermarking] ' . $e->getMessage());
}
}