2012-02-29 7 views
0

의 크기에 따라 내가 가지고 내가 http://dolcepixel.com/how-to-watermark-all-your-uploaded-images/ 내가 원래 이미지가 특정 크기 이하이면 다른 워터 마크 이미지를 사용하도록 코드를 수정해야다른 워터 마크 이미지 원본 이미지

에 공급하는 다음 코드.

150x150 미만인 경우 워터 마크를 적용하지 않는 것과 관련된 코드가 있지만 어떻게 워터 마크가 아닌 다른 워터 마크를 사용하도록 수정 될 수 있습니까?

$img_w = imagesx($image); 
$img_h = imagesy($image); 

을이 제거 :

if (eregi("MTP-logo", $img)) { 
    imagejpeg($image, null, $q); die(); 
} else { 
    $watermark = @imagecreatefrompng('watermark.png'); 
} 

놓고 if들 $ img_w 또는 $ img_h 같은에 따라이를 바탕으로

<?php 
//we tell the server to treat this file as if it wore an image 
header('Content-type: image/jpeg'); 
//image file path 
$img = $_GET['src']; 
//watermark position 
$p = $_GET['p']; if(!$p) $p = 'c'; 
$q = $_GET['q']; 
if(!$q || $q<0 || $q>100) $q = '93'; 
$filetype = substr($img,strlen($img)-4,4); 
$filetype = strtolower($filetype); 
if($filetype == ".gif") $image = @imagecreatefromgif($img); 
if($filetype == ".jpg") $image = @imagecreatefromjpeg($img); 
if($filetype == ".png") $image = @imagecreatefrompng($img); 
if (!$image) die(); 

//getting the image size for the original image 
$img_w = imagesx($image); 
$img_h = imagesy($image); 

//if the filename has 150x150 in it's name then we don't apply the watermark 
if (eregi("MTP-logo", $img)) { 
    imagejpeg($image, null, $q); die(); 
} else { 
    $watermark = @imagecreatefrompng('watermark.png'); 
} 
/* 
//if you want to use the watermark only on bigger images then use this instead of the condition above 
if ($img_w < "150") {//if image width is less then 150 pixels 
    imagejpeg($image, null, $q); die(); 
} else { 
    $watermark = @imagecreatefrompng('watermark.png'); 
} 
*/ 
//getting the image size for the watermark 
$w_w = imagesx($watermark); 
$w_h = imagesy($watermark); 
if($p == "tl") { 
    $dest_x = 0; 
    $dest_y = 0; 
} elseif ($p == "tc") { 
    $dest_x = ($img_w - $w_w)/2; 
    $dest_y = 0; 
} elseif ($p == "tr") { 
    $dest_x = $img_w - $w_w; 
    $dest_y = 0; 
} elseif ($p == "cl") { 
    $dest_x = 0; 
    $dest_y = ($img_h - $w_h)/2; 
} elseif ($p == "c") { 
    $dest_x = ($img_w - $w_w)/2; 
    $dest_y = ($img_h - $w_h)/2; 
} elseif ($p == "cr") { 
    $dest_x = $img_w - $w_w; 
    $dest_y = ($img_h - $w_h)/2; 
} elseif ($p == "bl") { 
    $dest_x = 0; 
    $dest_y = $img_h - $w_h; 
} elseif ($p == "bc") { 
    $dest_x = ($img_w - $w_w)/2; 
    $dest_y = $img_h - $w_h; 
} elseif ($p == "br") { 
    $dest_x = $img_w - $w_w; 
    $dest_y = $img_h - $w_h; 
} 
imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $w_w, $w_h); 
imagejpeg($image, null, $q); 
imagedestroy($image); 
imagedestroy($watermark); 

?> 

답변

2

당신이 그것을 할 수 있습니다 (폭과 높이를 얻는다) 이 :

if($img_w>1000)$watermark = @imagecreatefrompng('watermark1000.png'); 
else if($img_w>800)$watermark = @imagecreatefrompng('watermark800.png'); 
else if($img_w>600)$watermark = @imagecreatefrompng('watermark600.png'); 
else if($img_w>400)$watermark = @imagecreatefrompng('watermark400.png'); 
else if($img_w>200)$watermark = @imagecreatefrompng('watermark200.png'); 
else $watermark = @imagecreatefrompng('watermarkmini.png'); 
관련 문제