php로 워터마크 구현하기

php로 워터마크 구현하기


function fileUp($file, $fileTo)
{
global $HTTP_POST_FILES;
echo $HTTP_POST_FILES[$file]['name'];

if($HTTP_POST_FILES[$file]['name'])
{
if (is_uploaded_file($tmp = $HTTP_POST_FILES[$file]['tmp_name']))
{
unlink($fileTo);
return move_uploaded_file($tmp, $fileTo);
unlink($tmp);
}
}
}

function LoadImage($fName, $string) {
$file_ext = strtolower(substr(strrchr($fName,"."), 1)); //확장자
switch ($file_ext) {
case "jpg": case "jpeg":
$im = ImageCreateFromJPEG($fName);
break;
case "gif":
$im = ImageCreateFromGIF($fName);
break;
case "png":
$im = ImageCreateFromPNG($fName);
break;
}

if (!$im) {
$px = 7.5 * strlen($string);
$im = ImageCreatetruecolor($px, 12);
$bgc = ImageColorAllocate($im, 255, 255, 255);
$tc = ImageColorAllocate($im, 0, 0, 0);

ImageColorTransparent($im, $bgc);
ImageString($im,3,0,0,$string,$tc);
}
return $im;
}


function thumbnail($file, $fileTo, $width, $height)
{
Global $thumbLogo;

$src_im = LoadImage($file, $string);

$size[0] = ImageSX($src_im);
$size[1] = ImageSY($src_im);

$offsetX = 0;
$offsetXa = 0;
$offsetY = 0;
$offsetYa = 0;

if($height*$size[0] < $width*$size[1]) {
$offsetY = round(($size[0] * $height) / $width);
$offsetY = $size[1] - $offsetY;
$offsetYa = round($offsetY / 2);
} else {
$offsetX = round(($size[1] * $width) / $height);
$offsetX = $size[0] - $offsetX;
$offsetXa = round($offsetX / 2);
}

$dst_im = ImageCreatetruecolor($width,$height); //결과물 이미지 생성
ImageCopyResampled($dst_im,$src_im,0,0,$offsetXa,$offsetYa,$width,$height,ImageSX($src_im)-$offsetX,ImageSY($src_im)-$offsetY);
//ImageCopyResampled($dst_im,$src_im,$offsetXa,$offsetYa,0,0,$width,$height,ImageSX($src_im),ImageSY($src_im));
//만들기
//ImageCopyResized
//gdImageCopyResampled

if ($thumbLogo["on"] == "yes")
{
$im = LoadImage($thumbLogo["img"], $thumbLogo["string"]);
if($im)
{
$offsetX = $width - ImageSX($im) - 3;
$offsetY = $height - ImageSY($im) - 3;
ImageCopyMerge($dst_im,$im,$offsetX,$offsetY,0,0,ImageSX($im),ImageSY($im), $thumbLogo["opacity"]);
// ImageCopyResized($dst_im,$im,$offsetX,$offsetY,0,0,ImageSX($im),ImageSY($im),ImageSX($im),ImageSY($im)); //만들기
}
}

$file_ext = strtolower(substr(strrchr($fileTo,"."), 1));
if($file_ext == "jpg") // 저장하기
return ImageJPEG($dst_im, $fileTo, $thumbLogo["quality"]);
else if($file_ext == "gif")
return ImageGIF($dst_im, $fileTo);
else if($file_ext == "png")
return ImagePNG($dst_im, $fileTo);

}

function addLogo($file, $fileTo)
{
Global $itemImgLogo;

$src_im = ImageCreateFromJPEG($file);
$im = LoadImage($itemImgLogo["img"], $itemImgLogo["string"]);

$offsetX = ImageSX($src_im) - ImageSX($im) - 3;
$offsetY = ImageSY($src_im) - ImageSY($im) - 3;

ImageCopyMerge($src_im,$im,$offsetX,$offsetY,0,0,ImageSX($im),ImageSY($im), $itemImgLogo["opacity"]);
// ImageCopyResized($dst_im,$im,$offsetX,$offsetY,0,0,ImageSX($im),ImageSY($im),ImageSX($im),ImageSY($im)); //만들기

return ImageJPEG($src_im, $fileTo, $itemImgLogo["quality"]);
}



// 손톱이미지 크기
$thumbWidth = "100";
$thumbHeight = "100";


// 손톱이미지에 로고 넣기
$thumbLogo["on"] = "yes";
$thumbLogo["img"] = "thumb_mark.png";
$thumbLogo["opacity"] = "100";
$thumbLogo["quality"] = "105";
//$thumbLogo["string"] = "Rpack";


// 아이템 이미지에 로고 넣기
$itemImgLogo["on"] = "yes";
$itemImgLogo["img"] = "waterMark.png";
$itemImgLogo["opacity"] = "100";
$itemImgLogo["quality"] = "100";
//$itemImgLogo["string"] = "Rpack.com";

// 이미지 저장
$dirImg = "img/";
$dirThumb = "thumb/";


// 이미지 파일 업로드
if(fileUp("img01", $dirImg.$LII.".jpg"))
{
$tmp1[1] = "1"; // 파일 업로드 확인
thumbnail($dirImg.$LII.".jpg", $dirThumb.$LII.".jpg", $thumbWidth, $thumbHeight); // 손톱이미지 생성
if($itemImgLogo["on"]){
addLogo($dirImg.$LII.".jpg", $dirImg.$LII.".jpg"); // 원본 이미지에 로고 삽입
}
}
?>


< form METHOD=POST ACTION="" enctype="multipart/form-data">
< INPUT TYPE="file" NAME="img01">
< INPUT TYPE="submit">
< /form>
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기

Posted by 홍반장

2006/09/12 17:50 2006/09/12 17:50
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/1990

Trackback URL : http://tcbs17.cafe24.com/tc/trackback/1990

« Previous : 1 : ... 4414 : 4415 : 4416 : 4417 : 4418 : 4419 : 4420 : 4421 : 4422 : ... 6391 : Next »

블로그 이미지

- 홍반장

Archives

Recent Trackbacks

Calendar

«   2024/05   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Statistics Graph

Site Stats

Total hits:
197872
Today:
381
Yesterday:
379