DHTML 워터마크 적용하기 정보
DHTML 워터마크 적용하기본문
DHTML에 워터마크를 적용하시려는 분들을 위해서 올려봅니다.
워터마크 적용하는 소스를 이용해서 만들어본겁니다.
cheditor4 폴더 imageupload-class.php파일수정:
1. 윗부분에 아래소스 추가해주세요 ^^
function waterMark($fileInHD, $wmFile, $transparency = 60, $jpegQuality = 100, $WatermarkLocate = 0) {
$wmImg = imagecreatefromgif($wmFile);
$jpegImg = imagecreatefromjpeg($fileInHD);
$wmX=imagesx($jpegImg) - imagesx($wmImg);
$wmY=imagesy($jpegImg) - imagesy($wmImg);
switch ($WatermarkLocate) {
case 0: // 좌측상단
$ww = 0;
$wh = 0;
break;
case 1: // 가운데
$ww = $wmX/2;
$wh = $wmY/2;
break;
case 2: // 우측하단
$ww = $wmX;
$wh = $wmY;
break;
}
imagecopymerge($jpegImg, $wmImg, $ww, $wh, 0, 0, imagesx($wmImg), imagesy($wmImg), $transparency);
imagejpeg($jpegImg, $fileInHD, $jpegQuality);
}
2. 모든 chmod($this->path . $this->file["name"], 0644); 윗부분에 아래소스 추가해주세요.
$file = $this->path . $this->file["name"]; //저장 파일이겠죠 ^^
$overfile = "./img/mark.gif"; //마크 이미지 저장 경로겠죠 ^^ 주의할점은 cheditor4 폴더에 워터마크 찍으려는 이미지 경로로 적용해주세요.
waterMark($file, $overfile, 100, 100, 1); //저장 파일에 워터마크를 찍겠다는거겠죠 ^^
끝입니다.
워터마크 적용하는 소스를 이용해서 만들어본겁니다.
cheditor4 폴더 imageupload-class.php파일수정:
1. 윗부분에 아래소스 추가해주세요 ^^
function waterMark($fileInHD, $wmFile, $transparency = 60, $jpegQuality = 100, $WatermarkLocate = 0) {
$wmImg = imagecreatefromgif($wmFile);
$jpegImg = imagecreatefromjpeg($fileInHD);
$wmX=imagesx($jpegImg) - imagesx($wmImg);
$wmY=imagesy($jpegImg) - imagesy($wmImg);
switch ($WatermarkLocate) {
case 0: // 좌측상단
$ww = 0;
$wh = 0;
break;
case 1: // 가운데
$ww = $wmX/2;
$wh = $wmY/2;
break;
case 2: // 우측하단
$ww = $wmX;
$wh = $wmY;
break;
}
imagecopymerge($jpegImg, $wmImg, $ww, $wh, 0, 0, imagesx($wmImg), imagesy($wmImg), $transparency);
imagejpeg($jpegImg, $fileInHD, $jpegQuality);
}
2. 모든 chmod($this->path . $this->file["name"], 0644); 윗부분에 아래소스 추가해주세요.
$file = $this->path . $this->file["name"]; //저장 파일이겠죠 ^^
$overfile = "./img/mark.gif"; //마크 이미지 저장 경로겠죠 ^^ 주의할점은 cheditor4 폴더에 워터마크 찍으려는 이미지 경로로 적용해주세요.
waterMark($file, $overfile, 100, 100, 1); //저장 파일에 워터마크를 찍겠다는거겠죠 ^^
끝입니다.
추천
4
4
댓글 10개
감사 합니다 더불어님 엉엉엉
저는 안되네요. 몇번을 해봐도 왜 그럴까요? ^^
제트스윙님
마크찍으려는 이미지 경로를 찾지못해서 안되는것 같습니다.
cheditor4 폴더에 워터마크 찍으려는 이미지를 적용해주세요.
제가 사용한 경우($overfile = "./img/mark.gif";)는 cheditor4폴더에 img라는 폴더를 만들고 마크이미지를 적용한 경우거든요....
즐거운 하루되세요 ^^
마크찍으려는 이미지 경로를 찾지못해서 안되는것 같습니다.
cheditor4 폴더에 워터마크 찍으려는 이미지를 적용해주세요.
제가 사용한 경우($overfile = "./img/mark.gif";)는 cheditor4폴더에 img라는 폴더를 만들고 마크이미지를 적용한 경우거든요....
즐거운 하루되세요 ^^
잘 되네요. 잘 사용하겠습니다. 근데 png나 gif도 가능하면 좋을텐데요.^^
감사합니다..잘되네요..
이거 적용전의 이미지들도 적용되게 할순 없나요..?
이거 적용전의 이미지들도 적용되게 할순 없나요..?
음, 아래처럼 넣었는데 본문이미지 삽입도 안되네요.
뭐가 문제일까요?
cheditor4폴더 밑에 img 디렉토리만들고 그 안에 makr.gif 이름으로 파일도 만들어넣었는데요...ㅡㅡ
<?php
/*
** CHEditor Image Upload Class
**
*/
class uploader {
var $file;
var $errors;
var $accepted;
var $max_filesize;
var $max_image_width;
var $max_image_height;
function waterMark($fileInHD, $wmFile, $transparency = 60, $jpegQuality = 100, $WatermarkLocate = 0){
$wmImg = imagecreatefromgif($wmFile);
$jpegImg = imagecreatefromjpeg($fileInHD);
$wmX=imagesx($jpegImg) - imagesx($wmImg);
$wmY=imagesy($jpegImg) - imagesy($wmImg);
switch ($WatermarkLocate) {
case 0: // 좌측상단
$ww = 0;
$wh = 0;
break;
case 1: // 가운데
$ww = $wmX/2;
$wh = $wmY/2;
break;
case 2: // 우측하단
$ww = $wmX;
$wh = $wmY;
break;
}
imagecopymerge($jpegImg, $wmImg, $ww, $wh, 0, 0, imagesx($wmImg), imagesy($wmImg), $transparency);
imagejpeg($jpegImg, $fileInHD, $jpegQuality);
}
function max_filesize($size) {
$this->max_filesize = $size;
}
function max_image_size($width, $height) {
$this->max_image_width = $width;
$this->max_image_height = $height;
}
function upload($filename='', $accept_type='', $extention='') {
global $_FILES;
if (!$_FILES[$filename]['type']) return FALSE;
if (!$filename || $filename == "none") {
$this->errors[0] = "파일을 업로드 할 수 없습니다.";
$this->accepted = FALSE;
return FALSE;
}
$this->file = $_FILES[$filename];
$this->file['file'] = $filename;
if ($this->max_filesize) {
if ($this->file["size"] > $this->max_filesize) {
$this->errors[1] = "최대 파일 크기 오류: " . $this->max_filesize/1000 . "KB (" . $this->max_filesize . " bytes).";
$this->accepted = FALSE;
return FALSE;
}
}
if (preg_match("/image/", $this->file["type"])) {
$image = getimagesize($this->file["tmp_name"]);
if ($this->max_image_width || $this->max_image_height) {
$this->file["width"] = $image[0];
$this->file["height"] = $image[1];
if (($this->file["width"] > $this->max_image_width) || ($this->file["height"] > $this->max_image_height)) {
$this->errors[2] = "최대 이미지 크기 오류: " . $this->max_image_width . " x " . $this->max_image_height . " 픽셀";
$this->accepted = FALSE;
return FALSE;
}
}
switch ($image[2]) {
case 1:
$this->file["extention"] = ".gif"; break;
case 2:
$this->file["extention"] = ".jpg"; break;
case 3:
$this->file["extention"] = ".png"; break;
case 4:
$this->file["extention"] = ".swf"; break;
case 5:
$this->file["extention"] = ".psd"; break;
case 6:
$this->file["extention"] = ".bmp"; break;
case 7:
$this->file["extention"] = ".tif"; break;
case 8:
$this->file["extention"] = ".tga"; break;
default:
$this->file["extention"] = $extention; break;
}
}
else {
$this->file["extention"] = $extention;
}
if ($accept_type) {
if (preg_match("/".strtolower($accept_type)."/", strtolower($this->file["type"]))) {
$this->accepted = TRUE;
}
else {
$this->accepted = FALSE;
$this->errors[3] = preg_replace("/\|/", " 또는 ", $accept_type) . " 파일만 업로드 할 수 있습니다.";
}
}
else {
$this->accepted = TRUE;
}
return $this->accepted;
}
function save_file($path, $overwrite_mode="3"){
$this->path = $path;
if ($this->accepted) {
$this->file["name"] = $this->random_generator();
if (preg_match("/(\.)([a-z0-9]{2,5})$/", $this->file["name"])) {
$pos = strrpos($this->file["name"], ".");
if (!$this->file["extention"]) {
$this->file["extention"] = substr($this->file["name"], $pos, strlen($this->file["name"]));
}
$this->file['raw_name'] = substr($this->file["name"], 0, $pos);
}
else {
$this->file['raw_name'] = $this->file["name"];
if ($this->file["extention"]) {
$this->file["name"] = $this->file["name"] . $this->file["extention"];
}
}
switch($overwrite_mode) {
case 1:
$aok = move_uploaded_file($this->file["tmp_name"], $this->path . $this->file["name"]);
$file = $this->path . $this->file["name"]; //저장 파일이겠죠 ^^
$overfile = "./img/mark.gif"; //마크 이미지 저장 경로겠죠 ^^ 주의할점은 cheditor4 폴더에 워터마크 찍으려는 이미지 경로로 적용해주세요.
waterMark($file, $overfile, 100, 100, 1); //저장 파일에 워터마크를 찍겠다는거겠죠 ^^
chmod($this->path . $this->file["name"], 0644);
break;
case 2:
$copy = '';
$n = 1;
while (file_exists($this->path . $this->file['raw_name'] . $copy . $this->file["extention"])) {
$copy = "_copy" . $n;
$n++;
}
$this->file["name"] = $this->file['raw_name'] . $copy . $this->file["extention"];
$aok = move_uploaded_file($this->file["tmp_name"], $this->path . $this->file["name"]);
$file = $this->path . $this->file["name"]; //저장 파일이겠죠 ^^
$overfile = "./img/mark.gif"; //마크 이미지 저장 경로겠죠 ^^ 주의할점은 cheditor4 폴더에 워터마크 찍으려는 이미지 경로로 적용해주세요.
waterMark($file, $overfile, 100, 100, 1); //저장 파일에 워터마크를 찍겠다는거겠죠 ^^
chmod($this->path . $this->file["name"], 0644);
break;
case 3:
if (file_exists($this->path . $this->file["name"])){
$this->errors[4] = """ . $this->path . $this->file["name"] . "" 파일이 존재합니다.";
$aok = null;
}
else {
$aok = move_uploaded_file($this->file["tmp_name"], $this->path . $this->file["name"]);
$file = $this->path . $this->file["name"]; //저장 파일이겠죠 ^^
$overfile = "./img/mark.gif"; //마크 이미지 저장 경로겠죠 ^^ 주의할점은 cheditor4 폴더에 워터마크 찍으려는 이미지 경로로 적용해주세요.
waterMark($file, $overfile, 100, 100, 1); //저장 파일에 워터마크를 찍겠다는거겠죠 ^^
chmod($this->path . $this->file["name"], 0644);
}
break;
default:
break;
}
if(!$aok) {
unset($this->file['tmp_name']);
}
return $aok;
}
else {
$this->errors[3] = preg_replace("/\|/", " 또는 ", $accept_type) . " 파일만 업로드 할 수 있습니다.";
return FALSE;
}
}
function random_generator ($min=8, $max=32, $special=NULL, $chararray=NULL) {
$random_chars = array();
if ($chararray == NULL) {
$str = "abcdefghijklmnopqrstuvwxyz";
$str .= strtoupper($str);
$str .= "1234567890";
if ($special) {
$str .= "!@#$%";
}
}
else {
$str = $charray;
}
for ($i=0; $i<strlen($str)-1; $i++) {
$random_chars[$i] = $str[$i];
}
srand((float)microtime()*1000000);
shuffle($random_chars);
$length = rand($min, $max);
$rdata = '';
for ($i=0; $i<$length; $i++) {
$char = rand(0, count($random_chars) - 1);
$rdata .= $random_chars[$char];
}
return $rdata;
}
}
?>
뭐가 문제일까요?
cheditor4폴더 밑에 img 디렉토리만들고 그 안에 makr.gif 이름으로 파일도 만들어넣었는데요...ㅡㅡ
<?php
/*
** CHEditor Image Upload Class
**
*/
class uploader {
var $file;
var $errors;
var $accepted;
var $max_filesize;
var $max_image_width;
var $max_image_height;
function waterMark($fileInHD, $wmFile, $transparency = 60, $jpegQuality = 100, $WatermarkLocate = 0){
$wmImg = imagecreatefromgif($wmFile);
$jpegImg = imagecreatefromjpeg($fileInHD);
$wmX=imagesx($jpegImg) - imagesx($wmImg);
$wmY=imagesy($jpegImg) - imagesy($wmImg);
switch ($WatermarkLocate) {
case 0: // 좌측상단
$ww = 0;
$wh = 0;
break;
case 1: // 가운데
$ww = $wmX/2;
$wh = $wmY/2;
break;
case 2: // 우측하단
$ww = $wmX;
$wh = $wmY;
break;
}
imagecopymerge($jpegImg, $wmImg, $ww, $wh, 0, 0, imagesx($wmImg), imagesy($wmImg), $transparency);
imagejpeg($jpegImg, $fileInHD, $jpegQuality);
}
function max_filesize($size) {
$this->max_filesize = $size;
}
function max_image_size($width, $height) {
$this->max_image_width = $width;
$this->max_image_height = $height;
}
function upload($filename='', $accept_type='', $extention='') {
global $_FILES;
if (!$_FILES[$filename]['type']) return FALSE;
if (!$filename || $filename == "none") {
$this->errors[0] = "파일을 업로드 할 수 없습니다.";
$this->accepted = FALSE;
return FALSE;
}
$this->file = $_FILES[$filename];
$this->file['file'] = $filename;
if ($this->max_filesize) {
if ($this->file["size"] > $this->max_filesize) {
$this->errors[1] = "최대 파일 크기 오류: " . $this->max_filesize/1000 . "KB (" . $this->max_filesize . " bytes).";
$this->accepted = FALSE;
return FALSE;
}
}
if (preg_match("/image/", $this->file["type"])) {
$image = getimagesize($this->file["tmp_name"]);
if ($this->max_image_width || $this->max_image_height) {
$this->file["width"] = $image[0];
$this->file["height"] = $image[1];
if (($this->file["width"] > $this->max_image_width) || ($this->file["height"] > $this->max_image_height)) {
$this->errors[2] = "최대 이미지 크기 오류: " . $this->max_image_width . " x " . $this->max_image_height . " 픽셀";
$this->accepted = FALSE;
return FALSE;
}
}
switch ($image[2]) {
case 1:
$this->file["extention"] = ".gif"; break;
case 2:
$this->file["extention"] = ".jpg"; break;
case 3:
$this->file["extention"] = ".png"; break;
case 4:
$this->file["extention"] = ".swf"; break;
case 5:
$this->file["extention"] = ".psd"; break;
case 6:
$this->file["extention"] = ".bmp"; break;
case 7:
$this->file["extention"] = ".tif"; break;
case 8:
$this->file["extention"] = ".tga"; break;
default:
$this->file["extention"] = $extention; break;
}
}
else {
$this->file["extention"] = $extention;
}
if ($accept_type) {
if (preg_match("/".strtolower($accept_type)."/", strtolower($this->file["type"]))) {
$this->accepted = TRUE;
}
else {
$this->accepted = FALSE;
$this->errors[3] = preg_replace("/\|/", " 또는 ", $accept_type) . " 파일만 업로드 할 수 있습니다.";
}
}
else {
$this->accepted = TRUE;
}
return $this->accepted;
}
function save_file($path, $overwrite_mode="3"){
$this->path = $path;
if ($this->accepted) {
$this->file["name"] = $this->random_generator();
if (preg_match("/(\.)([a-z0-9]{2,5})$/", $this->file["name"])) {
$pos = strrpos($this->file["name"], ".");
if (!$this->file["extention"]) {
$this->file["extention"] = substr($this->file["name"], $pos, strlen($this->file["name"]));
}
$this->file['raw_name'] = substr($this->file["name"], 0, $pos);
}
else {
$this->file['raw_name'] = $this->file["name"];
if ($this->file["extention"]) {
$this->file["name"] = $this->file["name"] . $this->file["extention"];
}
}
switch($overwrite_mode) {
case 1:
$aok = move_uploaded_file($this->file["tmp_name"], $this->path . $this->file["name"]);
$file = $this->path . $this->file["name"]; //저장 파일이겠죠 ^^
$overfile = "./img/mark.gif"; //마크 이미지 저장 경로겠죠 ^^ 주의할점은 cheditor4 폴더에 워터마크 찍으려는 이미지 경로로 적용해주세요.
waterMark($file, $overfile, 100, 100, 1); //저장 파일에 워터마크를 찍겠다는거겠죠 ^^
chmod($this->path . $this->file["name"], 0644);
break;
case 2:
$copy = '';
$n = 1;
while (file_exists($this->path . $this->file['raw_name'] . $copy . $this->file["extention"])) {
$copy = "_copy" . $n;
$n++;
}
$this->file["name"] = $this->file['raw_name'] . $copy . $this->file["extention"];
$aok = move_uploaded_file($this->file["tmp_name"], $this->path . $this->file["name"]);
$file = $this->path . $this->file["name"]; //저장 파일이겠죠 ^^
$overfile = "./img/mark.gif"; //마크 이미지 저장 경로겠죠 ^^ 주의할점은 cheditor4 폴더에 워터마크 찍으려는 이미지 경로로 적용해주세요.
waterMark($file, $overfile, 100, 100, 1); //저장 파일에 워터마크를 찍겠다는거겠죠 ^^
chmod($this->path . $this->file["name"], 0644);
break;
case 3:
if (file_exists($this->path . $this->file["name"])){
$this->errors[4] = """ . $this->path . $this->file["name"] . "" 파일이 존재합니다.";
$aok = null;
}
else {
$aok = move_uploaded_file($this->file["tmp_name"], $this->path . $this->file["name"]);
$file = $this->path . $this->file["name"]; //저장 파일이겠죠 ^^
$overfile = "./img/mark.gif"; //마크 이미지 저장 경로겠죠 ^^ 주의할점은 cheditor4 폴더에 워터마크 찍으려는 이미지 경로로 적용해주세요.
waterMark($file, $overfile, 100, 100, 1); //저장 파일에 워터마크를 찍겠다는거겠죠 ^^
chmod($this->path . $this->file["name"], 0644);
}
break;
default:
break;
}
if(!$aok) {
unset($this->file['tmp_name']);
}
return $aok;
}
else {
$this->errors[3] = preg_replace("/\|/", " 또는 ", $accept_type) . " 파일만 업로드 할 수 있습니다.";
return FALSE;
}
}
function random_generator ($min=8, $max=32, $special=NULL, $chararray=NULL) {
$random_chars = array();
if ($chararray == NULL) {
$str = "abcdefghijklmnopqrstuvwxyz";
$str .= strtoupper($str);
$str .= "1234567890";
if ($special) {
$str .= "!@#$%";
}
}
else {
$str = $charray;
}
for ($i=0; $i<strlen($str)-1; $i++) {
$random_chars[$i] = $str[$i];
}
srand((float)microtime()*1000000);
shuffle($random_chars);
$length = rand($min, $max);
$rdata = '';
for ($i=0; $i<$length; $i++) {
$char = rand(0, count($random_chars) - 1);
$rdata .= $random_chars[$char];
}
return $rdata;
}
}
?>
DHTML 워터마크 적용하기
죄송한데요. 혹시 cheditor5용은 공개할 의향 없으세요.^^
잘 돌아가는 php 파일로 업로드 해주실 의향은 없으신가여?
DHTML 워터마크 적용하기