日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
PHP生成圖片水印和文字水印

之前很多讀者發(fā)郵件問我如何使用PHP生成水印,今天我就來給大家講解一下。本篇PHP教程使用了兩個函數(shù)來生成水?。簑atermark_text()和watermark_image()。你可以將本篇教程的示例整合到你的WEB項目中,比如上傳圖片的版權(quán)水印。

文本水印

我們使用函數(shù)watermark_text()來生成文本水印,你必須先指定字體源文件、字體大小和字體文本,具體代碼如下:

 
 
 
 
  1. $font_path = "GILSANUB.TTF"; // Font file
  2. $font_size = 30; // in pixcels
  3. $water_mark_text_2 = "phpfuns"; // Watermark Text
  4. function watermark_text($oldimage_name, $new_image_name)
  5. {
  6. global $font_path, $font_size, $water_mark_text_2;
  7. list($owidth,$oheight) = getimagesize($oldimage_name);
  8. $width = $height = 300;
  9. $image = imagecreatetruecolor($width, $height);
  10. $image_src = imagecreatefromjpeg($oldimage_name);
  11. imagecopyresampled($image, $image_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
  12. $blue = imagecolorallocate($image, 79, 166, 185);
  13. imagettftext($image, $font_size, 0, 68, 190, $blue, $font_path, $water_mark_text_2);
  14. imagejpeg($image, $new_image_name, 100);
  15. imagedestroy($image);
  16. unlink($oldimage_name);
  17. return true;
  18. }

可以在這里查看demo。

圖片水印

我們使用函數(shù)watermark_image()來生成圖片水印,你必須先水銀圖片的源文件。具體代碼如下:

 
 
 
 
  1. $image_path = "phpfuns.png";
  2. function watermark_image($oldimage_name, $new_image_name)
  3. /{
  4. global $image_path;
  5. list($owidth,$oheight) = getimagesize($oldimage_name);
  6. $width = $height = 300;
  7. $im = imagecreatetruecolor($width, $height);
  8. $img_src = imagecreatefromjpeg($oldimage_name);
  9. imagecopyresampled($im, $img_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
  10. $watermark = imagecreatefrompng($image_path);
  11. list($w_width, $w_height) = getimagesize($image_path);
  12. $pos_x = $width - $w_width;
  13. $pos_y = $height - $w_height;
  14. imagecopy($im, $watermark, $pos_x, $pos_y, 0, 0, $w_width, $w_height);
  15. imagejpeg($im, $new_image_name, 100);
  16. imagedestroy($im);
  17. unlink($oldimage_name);
  18. return true;
  19. }

你可以在這里查看demo。

上傳圖片表單

我們使用下面的表單來上傳圖片:

 
 
 
 
  1. $demo_image= "";
  2. if(isset($_POST['createmark']) and $_POST['createmark'] == "Submit")
  3. {
  4. $path = "uploads/";
  5. $valid_formats = array("jpg", "bmp","jpeg");
  6. $name = $_FILES['imgfile']['name'];
  7. if(strlen($name))
  8. {
  9. list($txt, $ext) = explode(".", $name);
  10. if(in_array($ext,$valid_formats) && $_FILES['imgfile']['size'] <= 256*1024)
  11. {
  12. $upload_status = move_uploaded_file($_FILES['imgfile']['tmp_name'], $path.$_FILES['imgfile']['name']);
  13. if($upload_status){
  14. $new_name = $path.time().".jpg";
  15. // Here you have to user functins watermark_text or watermark_image
  16. if(watermark_text($path.$_FILES['imgfile']['name'], $new_name))
  17. $demo_image = $new_name;
  18. }
  19. }
  20. else
  21. $msg="File size Max 256 KB or Invalid file format.";
  22. }
  23. }
  24. ?>
  25. // HTML Code
  26. Upload Image
  27. Image :
  28. if(!emptyempty($demo_image))
  29. echo '';
  30. ?>

實際上就是PHP的gd庫,一切就是這么簡單!

此處下載


名稱欄目:PHP生成圖片水印和文字水印
網(wǎng)頁網(wǎng)址:http://www.dlmjj.cn/article/dhdpepi.html