加水印 用來為圖片加浮水印的PHP類

WBOY
發布: 2016-07-29 08:37:46
原創
856 人瀏覽過

複製程式碼 程式碼如下:


/*   
* 功能:PHP圖片水印 (水印支持圖片或文字)   
* 參數:   
*     $groundImage   背景圖片,即需要加水印的圖片,暫只支援GIF,JPG,PNG格式;   
*     $waterPos     水印位置,10種狀態,0為隨機位置;為頂端居中,3為頂端居右;   
*                 4為中部居左,5為中部居中,6為中部居右    🠎>*  底端居中,9為底端居右;   
*     $waterImage圖片浮水印,即作為浮水印的圖片,暫只支援GIF,JPG,PNG格式;   
*     $waterText     文字水印,即將文字當作水印,支援ASCII碼,不支援大小,值為1、2、3、4或5,預設為5;   
*     $textColor     文字顏色,且值為十六進位色彩值,預設為#FF0000(紅色);  文字顏色,值為十六進位色彩值,預設為#FF0000(紅色); >* 注意:Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG   
*     $waterImageText且$water$water    
*     當$waterImage有效時,參數$waterString、$stringFont、$stringColor皆不生效。   
*     加浮水印後的圖片的檔案名稱和 $groundImage 一樣。
* 作者:longware @ 2004-11-3 14:15:13   
*/   
function imageWaterMark($groundImage,$waterPos🎜>function imageWaterMark($groundImage,$waterPos=0,$waterImwaterage=$” textF
{    
  $isWaterImage = FALSE;    
  $formatMsg = 「暫不支援此檔案格式,請以圖片處理軟體將圖片轉換為資料、JNGJ」;    
  //讀取水印檔案    
  if(!emptyempty($waterImage) && file_exists($water Image = TRUE;    
    $water_info = getimagesize($ waterImage);    
    $water_w   = $water_info[0];//取得水印圖片的寬         {    
        case 1:$water_im  case 2:$water_im = imagecreatefromjpeg($waterImage);break;    
case 3:$water_im = imagecreatefrompng($waterImage);break;    
        default:die($formatM   
  //讀取背景圖片    
  if(!emptyempty( $groundImage) && file_exists($groundImage))    
  {    
     ground_info[0];//取得背景圖片的寬    
    $ground_h = $ground_info[1];//取得背景圖片的高    
    switch($ground_info[2])//取得背景圖片的格式             case 2:$ground_im = imagecreatefromjpeg($groundImage);break    age);break;    
        default:die($formatMsg);    
    }    
  }    
  else   
  {    ”);    
  }    
  //水印位置    
  if($isWaterIm  = $water_w;    
    $h = $water_h;    
    $label = 「圖片的」;    
  }    
  else//文字水印    $textFont*5),0,”./cour.ttf” ,$waterText);//取得使用 TrueType 字體的文本的範圍    
    $w = $temp[2] - $temp[6];    ;    
    unset($temp);    
    $label = 「文字區域」;    _h {    
    echo 「需要加浮水印的圖片的長度或寬度比水印」.$label.」還小,無法產生浮水印!」;    
    return;    
  }    
  switch($waterPos)    
        $posX = rand(0,($ground_w - $w)) ;    
        $posY = rand(0,($ground_h - $h));             $posX = 0;    
        $posY = 0;    
        break;    
    case 2://2為頂居中   / 2;    
        $posY = 0;    
        break; 🎜>    case 3://3為頂端居右    
        $posX = $ground_w  
        break;    
    case 4://4為中部居左    
        $posX = 0;    
        $posY =      
    case 5://5為中部居中    
        $posX = ($ground_w -     $posX = ($ground_w - $w) / 2;    
        $posY = ($ground_h - $h) /    ase 6://6為中部居右    
        $posX = $ground_w - $ w;    
        $posY = ($ground_h - $h) / 2;             $posX = 0;    
        $$ $ground_h - $h;    
        break;    
    case 8://8為底端居中$ - $w) / 2;    
        $posY = $ground_h - $ h;    
        break;    
    case 9://9為底端為右住者    
        $posY = $ground_h - $h;    
        break;
    default://隨機    
        $posX = rand(0,($ground_w - $.  - $h));    
        break ;      
  }
  //設定影像的混合顏色模式    
  imagealphablending($ground_im, true);    
     imagecopy($ground_im, $water_im, $ posX, $posY, 0, 0, $water_w,$water_h);//拷貝水印到目標文件          
  }  
    if( !emptyempty($textColor) && (strlen($textColor)==7) )    
    {    
           $G = hexdec(substr($textColor,3, 2));    
        $B = hexdec(substr($textColor,5));             die(」水印文字顏色格式不正確!」);    
    }    
    imagestring ( $ground_im,          
  }    
//產生浮水印後的圖片    
  @unlink($groundImage);    
  switch($ground_info[2])//   $ground_im, $groundImage);break;    
    case 2:imagejpeg($ground_im,$groundImage);break;    
    default:die($errorMsg) ;    
  }    
  //釋放記憶體    
  if(isset($water_info)) unset($water_info);  if(isset($water_info)) unset($water_info); );    
  unset ($ground_info);    
  imagedestroy($ground_im);     
}    
//———————————————————————————— ——    
$id=$_REQUEST['id'];    
$num = count($_FILES['userfile']['name']);   );    
print_r($_FILES['userfile']['name']);    
echo $num;    
echo 「
」;
 for($i=0;$i  if(isset($_FILES) && !emptyempty($_FILES['userfile']))& && !emptyempty($_FILES['userfile']) ['size']>0)    
{    
  $uploadfile = 「./」.time().」_」.$_FILES['userfile'][name][$i]; 「
」;    
  echo $uploadfile;    
  if (copy($_FILES['userfile']['tmp_name'][$upi], ($_FILES['userfile']['tmp_name'][$i], $    echo 「 OK
”;    
    //文字水印    
    //imageWaterMark($uploadfile,5,",  fo.lvyecc.info》,「5)」#occ >    //圖片水印    
    $waterImage=”logo_ok1.gif」;//水印圖片路徑    
  cho “加水印 用來為圖片加浮水印的PHP類”;    
  }    
  else   
  {  }    
}    
 }    
}
?>    

    
for($a+$ {    
 echo 「檔案: 
」;    
}    上傳」>    
    


以上就介紹了加浮水印 用來為圖片加浮水印的PHP類,包括了加水印方面的內容,希望對PHP教學有興趣的朋友有幫助。


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!