그누보드 [G4] 이미지에 워터마크 넣기
페이지 정보
본문
====================================================
bbs/write_update.php
====================================================
109~164행 추가
----------------------------------------------------
// 이미지에 워터마크 넣기
// PHP > 4.0, GD > 2.0.1
// WatermarkImage("원본이미지","겹처지는이미지","투명도","화질",[겹치는이미지위치(0,1,2)]);
function WatermarkImage($CanvasImage, $WatermarkImage /* MUST BE PNG */, $Opacity=30, $Quality=70, $WatermarkLocate=1)
{
// create true color canvas image:
$canvas_src = imagecreatefromjpeg($CanvasImage);
$canvas_w = ImageSX($canvas_src);
$canvas_h = ImageSY($canvas_src);
$canvas_img = imagecreatetruecolor($canvas_w, $canvas_h);
imagecopy($canvas_img, $canvas_src, 0,0,0,0, $canvas_w, $canvas_h);
imagedestroy($canvas_src); // no longer needed
// create true color overlay image:
$overlay_src = imagecreatefrompng($WatermarkImage);
$overlay_w = ImageSX($overlay_src);
$overlay_h = ImageSY($overlay_src);
$overlay_img = imagecreatetruecolor($overlay_w, $overlay_h);
imagecopy($overlay_img, $overlay_src, 0,0,0,0, $overlay_w, $overlay_h);
imagedestroy($overlay_src); // no longer needed
// setup transparent color (pick one):
$black = imagecolorallocate($overlay_img, 0x00, 0x00, 0x00);
$white = imagecolorallocate($overlay_img, 0xFF, 0xFF, 0xFF);
$magenta = imagecolorallocate($overlay_img, 0xFF, 0x00, 0xFF);
// and use it here:
imagecolortransparent($overlay_img, $white);
// 워터마크 이미지의 위치(기본값은 가운데 1입니다.)
switch ($WatermarkLocate) {
case 0: // 좌측상단
$ww = 0;
$wh = 0;
break;
case 1: // 가운데
$ww = ($canvas_w / 2) - ($overlay_w / 2);
$wh = $canvas_h - ($overlay_h);
break;
case 2: // 우측하단
$ww = $canvas_w - ($overlay_w);
$wh = $canvas_h - ($overlay_h);
break;
}
// copy and merge the overlay image and the canvas image:
imagecopymerge($canvas_img, $overlay_img, $ww,$wh,0,0, $overlay_w, $overlay_h, $Opacity);
imagejpeg($canvas_img, $CanvasImage, $Quality);
/*
// output:
header("Content-type: image/jpeg");
imagejpeg($canvas_img, '', $Quality);
*/
imagedestroy($overlay_img);
imagedestroy($canvas_img);
}
----------------------------------------------------
238~241행 추가
----------------------------------------------------
// WatermarkImage("원본이미지","겹처지는이미지","투명도","화질",[겹치는이미지위치(0,1,2)]);
// 겹치는이미지위치값이 0이면 좌측상단, 1이면 가운데, 2이면 우측하단
$overfile = "$g4[path]/overlay.png";
WatermarkImage("$dest_file", $overfile, 40, 70, 1);
----------------------------------------------------
//워터마크기능
원작성자 : 후룬 https://sir.kr/g4_tiptech/2979
bbs/write_update.php
====================================================
109~164행 추가
----------------------------------------------------
// 이미지에 워터마크 넣기
// PHP > 4.0, GD > 2.0.1
// WatermarkImage("원본이미지","겹처지는이미지","투명도","화질",[겹치는이미지위치(0,1,2)]);
function WatermarkImage($CanvasImage, $WatermarkImage /* MUST BE PNG */, $Opacity=30, $Quality=70, $WatermarkLocate=1)
{
// create true color canvas image:
$canvas_src = imagecreatefromjpeg($CanvasImage);
$canvas_w = ImageSX($canvas_src);
$canvas_h = ImageSY($canvas_src);
$canvas_img = imagecreatetruecolor($canvas_w, $canvas_h);
imagecopy($canvas_img, $canvas_src, 0,0,0,0, $canvas_w, $canvas_h);
imagedestroy($canvas_src); // no longer needed
// create true color overlay image:
$overlay_src = imagecreatefrompng($WatermarkImage);
$overlay_w = ImageSX($overlay_src);
$overlay_h = ImageSY($overlay_src);
$overlay_img = imagecreatetruecolor($overlay_w, $overlay_h);
imagecopy($overlay_img, $overlay_src, 0,0,0,0, $overlay_w, $overlay_h);
imagedestroy($overlay_src); // no longer needed
// setup transparent color (pick one):
$black = imagecolorallocate($overlay_img, 0x00, 0x00, 0x00);
$white = imagecolorallocate($overlay_img, 0xFF, 0xFF, 0xFF);
$magenta = imagecolorallocate($overlay_img, 0xFF, 0x00, 0xFF);
// and use it here:
imagecolortransparent($overlay_img, $white);
// 워터마크 이미지의 위치(기본값은 가운데 1입니다.)
switch ($WatermarkLocate) {
case 0: // 좌측상단
$ww = 0;
$wh = 0;
break;
case 1: // 가운데
$ww = ($canvas_w / 2) - ($overlay_w / 2);
$wh = $canvas_h - ($overlay_h);
break;
case 2: // 우측하단
$ww = $canvas_w - ($overlay_w);
$wh = $canvas_h - ($overlay_h);
break;
}
// copy and merge the overlay image and the canvas image:
imagecopymerge($canvas_img, $overlay_img, $ww,$wh,0,0, $overlay_w, $overlay_h, $Opacity);
imagejpeg($canvas_img, $CanvasImage, $Quality);
/*
// output:
header("Content-type: image/jpeg");
imagejpeg($canvas_img, '', $Quality);
*/
imagedestroy($overlay_img);
imagedestroy($canvas_img);
}
----------------------------------------------------
238~241행 추가
----------------------------------------------------
// WatermarkImage("원본이미지","겹처지는이미지","투명도","화질",[겹치는이미지위치(0,1,2)]);
// 겹치는이미지위치값이 0이면 좌측상단, 1이면 가운데, 2이면 우측하단
$overfile = "$g4[path]/overlay.png";
WatermarkImage("$dest_file", $overfile, 40, 70, 1);
----------------------------------------------------
//워터마크기능
원작성자 : 후룬 https://sir.kr/g4_tiptech/2979
댓글목록
등록된 댓글이 없습니다.