YesYo.com MintState Forums
뒤로    YesYo.com MintState BBS > Tech > PHP
검색
멤버이름    오토
비밀번호 
 

워터마크 출력

페이지 정보

작성자 MintState 댓글 0건 조회 11,859회 작성일 08-11-03 11:32

본문

워터마크 출력

폰트를 이용한 글자 입히기
<? 
$font_size = 100; // 글자 크기 
$opacity = 10; // 투명도 높을수록 불투명 
$font_path = "arial.ttf";  //폰트 패스 
$string = "waterMark";  // 찍을 워터마크 

$image = "11.jpg"; //이미지

$image_name = explode(".",$image); 
$image_targ = $image_name[0]."_marked.jpg";  // 워터마크가 찍혀 저장될 이미지 

$image_org = $image; // 원본 이미지를 다른 이름으로 저장 
$image = imagecreatefromjpeg($image); // JPG 이미지를 읽고 

$w = imagesx($image); 
$h = imagesy($image);  

$text_color = imagecolorallocate($image,100,100,100); // 텍스트 컬러 지정 

// 적당히 워터마크가 붙을 위치를 지정 
$text_pos_x = $font_size; 
$text_pos_y = $h - $font_size; 

imagettftext($image, $font_size, 0, $text_pos_x, $text_pos_y, $text_color, $font_path, $string);  // 읽은 이미지에 워터마크를 찍고 
 
$image_org = imagecreatefromjpeg($image_org); // 원본 이미지를 다시한번 읽고 
  
imagecopymerge($image,$image_org,0,0,0,0,$w,$h,$opacity); // 원본과 워터마크를 찍은 이미지를 적당한 투명도로 겹치기 

imagejpeg($image, $image_targ, 90); // 이미지 저장. 해상도는 90 정도 
  
imagedestroy($image); 
imagedestroy($image_org); 

 
echo "<img src=$image_targ>"; // 워터마크가 찍혀 저장된 이미지 출력 
?>


이미지 입히기
<?
/******************************************************************************
Program: waterMark.php
Description : 서비스 이미지에 워터마크 적용하기
Author      : Ryu Jee Hyoung
CreateDate  : 2007.01.18
CopyRight   : Copyright(c) 청명공자 All Right Reserved.
UpdateDate  :
Todo        :
 워터마크가 적용되도록 이미지 URL 변경
 - 사용법
 > $img_url = http://localhost/images/test.jpg;
 > $img_url = waterMark($img_url);
 > echo $img_url;
******************************************************************************/
function waterMark($image,$thumbW=null,$thumbH=null)
{
  $argTmp = $thumbW."|".$thumbH."|".$image;
  $arg = base64_encode($argTmp);
  $arg = urlencode($arg);
  $img_info = @getImageSize($image);
  if($img_info[2] == 6) {
    $chgURL = $image;
  }
  else {
    $chgURL = "http://DOMAIN/imgView.php?image=$arg";
  }

  return $chgURL;
}

$img_url = 'http://DOMAIN/11.png';
$img_url = waterMark($img_url);
echo "<img src='".$img_url."'>";
?>


<?
/******************************************************************************
Program: imgView.php
Description : 서비스 이미지에 워터마크 적용하기
Author      : Ryu Jee Hyoung
CreateDate  : 2007.01.18
CopyRight   : Copyright(c) 청명공자 All Right Reserved.
UpdateDate  :
Todo        :
******************************************************************************/
flush();
 
# 특정경로에 워터마크 처리할 이미지가 존재해야 함!!
# 워터마크 이미지는 필히 JPG 여야 합니다.
define("WATERMARK", "/home/NAME/public_html/12.jpg");
 
header("Content-type: image/jpeg");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
 
$photoTmp = base64_decode($image);
$photo = $photoTmp; # waterMarkImage($arg) 이런 형식(w,h가 지정이 안된 경우)으로 사용된 것
if (ereg("\|",$photo)) {
  # waterMarkImage($arg,100,50) 이런 형식(w,h가 지정된 경우)으로 사용된 것
  list($w1,$h1,$photo) = explode("|", $photoTmp, 3);
  $thumb_w1 = $w1;
  $thumb_h1 = $h1;
}
$photo = urldecode($photo); # %C24%.... 이런식으로 encode되어 오는 파일오류를 방지

$img_info = getImageSize($photo);
$photo = ereg_replace("%","%25",$photo);
$image_url = urldecode($photo);
if (!@fopen($image_url, "r")) {
  $dst_img = imagecreatefromjpeg(WATERMARK);
  $res = imagejpeg($dst_img, "", 100);
  die();
}
$file = pathinfo($image_url);
if ($img_info[2] == "1") {
  $file["extension"] = "GIF";
}
else if ($img_info[2] == "2") {
  $file["extension"] = "JPG";
}
else if ($img_info[2] == "3") {
  $file["extension"] = "PNG";
}
switch(strtoupper($file["extension"])) {
  case "JPEG":
    $src_img = imagecreatefromjpeg($image_url);
    break;
  case "JPG":
    $src_img = imagecreatefromjpeg($image_url);
    break;
  case "GIF":
    $src_img = imagecreatefromgif($image_url);
    break;
  case "PNG":
    $src_img = imagecreatefrompng($image_url);
    break;
}
$src_w = imagesx($src_img);
$src_h = imagesy($src_img);
$portion = $src_h / $src_w;
 
# w, h값이 있으면 thumbnail로 보여주기
if(!is_numeric($w1) || empty($w1)) $w1 = $img_info[0];
if(!is_numeric($h1) || empty($h1)) $h1 = $img_info[1];
$dest_w = $w1;
$dest_h = $h1;
$dst_img = imagecreatetruecolor($dest_w, $dest_h);
 
# 배경이미지 흰색으로 채우는 부분 - 투명이미지가 이상하게 보이는 현상을 방지
$white = imagecolorallocate($dst_img,255,255,255);
imagefill($dst_img, 0, 0, $white);

imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $dest_w, $dest_h, $src_w, $src_h);
imagedestroy($src_img);
flush();
$watermark = imagecreatefromjpeg(WATERMARK);
$watermark_w = imagesx($watermark);
$watermark_h = imagesy($watermark);
$resize_w = $watermark_w;
$resize_h = $watermark_h;
if ($dest_w < 100) {
  $resize_w = $watermark_w / 2;
  $resize_h = $watermark_h / 2;
}
else if ($dest_h < 100) {
  $resize_w = $watermark_w / 2;
  $resize_h = $watermark_h / 2;
}
$overlay_img = imagecreatetruecolor($watermark_w, $watermark_h);
imagecopyresized($overlay_img, $watermark, 0, 0, 0, 0, $resize_w, $resize_h, $watermark_w, $watermark_h);
imagedestroy($watermark);
$white = imagecolorallocate($overlay_img, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($overlay_img, 0x00, 0x00, 0x00);
imagecolortransparent($overlay_img, $black);
 
# 워터마크 중앙에 배치
$offsetX = ($dest_w - $watermark_w - 3) / 2;
$offsetY = ($dest_h - $watermark_h - 3) / 2;
# 워터마크 좌상단에 배치
# $offsetX = 3;
# $offsetY = 3;
# 워터마크 우상단에 배치
# $offsetX = $dest_w - $watermark_w - 3;
# $offsetY = $dest_h - $watermark_h - 3;
 
# w, h값이 있으면 thumbnail로 보여주되 워터마크 적용안함!!
if (empty($thumb_w1) && empty($thumb_h1)) imagecopymerge($dst_img,$overlay_img,$offsetX,$offsetY,0,0,$watermark_w,$watermark_h, 30);
imagedestroy($overlay_img);
$res = imagejpeg($dst_img, "", 100);
imagedestroy($dst_img);
flush();
exit;
?>

댓글목록

등록된 댓글이 없습니다.

Total 165건 3 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
115 MintState 14497 11-10
114 MintState 16157 11-10
113 MintState 17094 11-10
112 MintState 21225 11-10
111 MintState 12460 11-10
110 MintState 30530 11-10
109 MintState 15809 11-10
108 MintState 14657 11-10
107 MintState 14548 11-10
106 MintState 12587 11-10
105 MintState 20792 11-10
104 MintState 12967 11-10
103 MintState 12824 11-10
102 MintState 19978 11-10
101 MintState 11431 11-10
100 MintState 12519 11-10
99 MintState 20270 11-10
98 MintState 14291 11-10
97 MintState 12901 11-10
96 MintState 11373 11-10
95 MintState 13288 11-10
열람중 MintState 11860 11-03
93 MintState 11304 11-03
92 MintState 12512 11-03
91 MintState 15520 11-03
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™