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

내가 산이되기 위하여 - 이근배

내가 산이되기 위하여 - 이근배

어느 날 문득
서울 사람들의 저자거리에서
헤매고 있는 나를 보았을 때
산이 내 곁에 없는 것을 알았다
낮도깨비같이 덜그럭거리며
쓰레기더미를 뒤적이며
사랑 따위를 팔고 있는 동안
산이 떠나버린 것을 몰랐다
내가 술을 마시면
같이 비틀거리고
내가 누우면 따라서 눕던
늘 내가 되어 주던
산을 나는 잃어버렸다
내가 들르는 술집 어디
만나던 여자의 살냄새 어디
두리번거리고 찾아도
산은 보이지 않았다
아주 산이 가버린 것을 알았을 때
나는 피리를 불기 시작했다
내가 산이 되기 위하여

//--------------

과연 내 산은 어디에 있는것일까?
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기

Posted by 홍반장

2006/09/12 10:05 2006/09/12 10:05
Response
No Trackback , a comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/1989

농담 - 이문재

농 담 - 이문재

문득 아름다운 것과 마주쳤을 때
지금 곁에 있으면 얼마나 좋을까, 하고
떠오르는 얼굴이 있다면 그대는
사랑하고 있는 것이다

그윽한 풍경이나
제대로 맛을 낸 음식 앞에서
아무도 생각하지 않는 사람
그 사람은 정말 강하거나
아니면 진짜 외로운 사람이다

종소리를 더 멀리 내보내기 위하여
종은 더 아파야 한다
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기

Posted by 홍반장

2006/09/12 10:04 2006/09/12 10:04
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/1988

깨끗한 얼굴

한 아이는 깨끗한 얼굴,
한 아이는 더러운 얼굴을 하고 굴뚝에서 내려왔다.
얼굴이 더러운 아이는 깨끗한 얼굴의 아이를 보고
자기도 깨끗하다고 생각한다. 이와 반대로
깨끗한 얼굴을 한 아이는 상대방의 더러운 얼굴을 보고
자기도 더럽다고 생각할 것이다.


- 조세희의《난장이가 쏘아올린 작은 공》중에서 -


* 사는 것이 굴뚝을 타는 것과 같습니다.
얼굴에 숯검정이 묻지 않을 수가 없습니다.
그러나 굴뚝을 내려왔으면 자기 얼굴부터 닦는 것이
순서입니다. 깨끗한 얼굴을 먼저 보여야 그 얼굴이
상대방에게는 자신을 비추는 거울이 됩니다.
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기

Posted by 홍반장

2006/09/12 09:18 2006/09/12 09:18
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/1987


블로그 이미지

- 홍반장

Archives

Recent Trackbacks

Calendar

«   2006/09   »
          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
Statistics Graph

Site Stats

Total hits:
188739
Today:
208
Yesterday:
717