사이트 내 전체검색
PHP
썸네일, 워터마크
로빈아빠
https://cmd.kr/php/319 URL이 복사되었습니다.

본문

function createThumb($imgWidth, $imgHeight, $imgSource, $name)
{
 global $saveDir;

 $thumb = $saveDir."thumb";
 $thumbName = $thumb."/".$name;

 if(!is_dir($thumb))
 {
  mkdir($thumb);
  chmod($thumb, 0707);
 }

 $size = getimagesize($imgSource);
 if ($size[2] == 1)
  $source = imagecreatefromgif($imgSource);
 else if ($size[2] == 2)
  $source = imagecreatefromjpeg($imgSource);
 else if ($size[2] == 3)
  $source = imagecreatefrompng($imgSource);
 else
  return 0;

 $rate = $imgWidth / $size[0];
 $height = (int)($size[1] * $rate);

 if ($size[0] < $imgWidth || $size[1] < $imgHeight) {
  $xWidth = $imgWidth;
  $xHeight = $imgHeight;
  $height = $imgHeight;
 } else {
  $xWidth = $size[0];
  $xHeight = $size[1];
 }

 $target = imagecreatetruecolor($imgWidth, $imgHeight);
 $white = imagecolorallocate($target, 255, 255, 255); 
 imagefilledrectangle($target, 0, 0, $imgWidth, $imgHeight, $white);
 imagecopyresampled($source, $source, 0, 0, 0, 0, $imgWidth, $height, $xWidth, $xHeight);
 imagecopy($target, $source, 0, 0, 0, 0, $imgWidth, $imgHeight);

 imagejpeg($target, $thumbName, 100);
 chmod($thumbName, 0707);
}

function WarterMark($imgSource)
{
    $size = getimagesize($imgSource);

    if ($size[2] == 1)
        $source = imagecreatefromgif($imgSource);
    else if ($size[2] == 2)
        $source = imagecreatefromjpeg($imgSource);
    else if ($size[2] == 3)
        $source = imagecreatefrompng($imgSource);
    else
        return 0;

    $imgWidth = $size[0];
    $imgHeight = $size[1];

    $target = imagecreatetruecolor($imgWidth, $imgHeight);

    imagecopy($target, $source, 0, 0, 0, 0, $imgWidth, $imgHeight);

    $loveColor = imagecolorallocate($target, 227, 210, 115);
 
 imagestring($target, 5, 10, 10, "WWW.119LOVE.NET", $loveColor);
 
 unlink($imgSource);
    imagejpeg($target, $imgSource, 100);
    chmod($imgSource, 0707);
}

=========== emul 에서 사용한 함수 ===============
function createThumb($imgWidth, $imgHeight, $imgSource)
{
 $size = getimagesize($imgSource);

 if ($size[2] == 1) $source = imagecreatefromgif($imgSource);
 else if ($size[2] == 2) $source = imagecreatefromjpeg($imgSource);
 else if ($size[2] == 3) $source = imagecreatefrompng($imgSource);
 else return 0;

 imagedestroy($imgSource);

 $rate = $imgWidth / $size[0];
 $height = (int)($size[1] * $rate);

 if ($size[0] < $imgWidth || $size[1] < $imgHeight)
 {
  $xWidth = $imgWidth;
  $xHeight = $imgHeight;
  $height = $imgHeight;
 }
 else
 {
  $xWidth = $size[0];
  $xHeight = $size[1];
 }

 $target = imagecreatetruecolor($imgWidth, $imgHeight);
 $white = imagecolorallocate($target, 255, 255, 255); 
 imagefilledrectangle($target, 0, 0, $imgWidth, $imgHeight, $white);
 imagecopyresampled($source, $source, 0, 0, 0, 0, $imgWidth, $height, $xWidth, $xHeight);
 imagecopy($target, $source, 0, 0, 0, 0, $imgWidth, $imgHeight);

 imagejpeg($target, $imgSource, 100);
 chmod($imgSource, 0606);
 imagedestroy($source);
}

// WatermarkImage("원본이미지","겹처지는이미지","투명도","화질",[겹치는이미지위치(0,1,2)]);
function WatermarkImage($CanvasImage, $WatermarkImage, $Opacity=30, $Quality=70, $WatermarkLocate=1)
{
 // create true color canvas image:
 $size = getimagesize($CanvasImage);

 if ($size[2] == 1) $canvas_src = imagecreatefromgif($CanvasImage);
 else if ($size[2] == 2) $canvas_src = imagecreatefromjpeg($CanvasImage);
 else if ($size[2] == 3) $canvas_src = imagecreatefrompng($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:
 $size2 = getimagesize($WatermarkImage);
 if ($size2[2] == 1) $overlay_src = imagecreatefromgif($WatermarkImage);
 else if ($size2[2] == 2) $overlay_src = imagecreatefromjpeg($WatermarkImage);
 else if ($size2[2] == 3) $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, $black);

 // 워터마크 이미지의 위치(기본값은 가운데 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);

 imagedestroy($overlay_img);
 imagedestroy($canvas_img);
}

function getGameImage($bo_table, $wr_id)
{
 global $g4;

 $sql = "Select bf_file From ".$g4[board_file_table]." Where bo_table = '".$bo_table."' and wr_id = ".$wr_id." and bf_no = 0";

 $data = sql_fetch($sql);
 $bf_file = $data["bf_file"];
 
 $imgSource = $g4[path]."/data/file/".$bo_table."/".$bf_file;

 return $imgSource;
}

$imgSource = getGameImage($bo_table, $wr_id);

createThumb(142, 105, $imgSource); // 이리지 리사이징

$overfile = "$g4[path]/images/emul_mark.png";
WatermarkImage($imgSource, $overfile, 100, 100, 2); // 사이트 로고 워터마킹

댓글목록

등록된 댓글이 없습니다.

PHP
871 (5/18P)

Search

Copyright © Cmd 명령어 52.15.161.188