php添加文字水印文檔介紹內容,word添加內容文字水印

本文目錄一覽:

php如何給圖片加文字水印

我知道的有三種,都是使用GD庫的image函數

一種是直接在圖片上寫文字

imagefttext();

一種是帶透明度的水印圖片

imagecopy();

還有一種是可以自定義水印圖片透明度的

imagecopymerge();

你想要什麼效果,可以接着細說

誰有能用的php給圖片加文字水印,最好有使用方法,注意:一定是能用的,功能強不強大另說

?php

/*PHP圖片加文字水印類庫

QQ:3697578482 傷心的歌

該類庫暫時只支持文字水印,位置為右下角,顏色隨機

調用方法:

1、在需要加水印的文件頂部引入類庫:

include_once ‘imageClass.php’;

2、聲明新類:

$tpl=new image_fu;

3、給圖片水印提供參數:

$tpl-img(圖片路徑,水印文字,字體路徑,字體大小,字體角度);

比如:$tpl-img(‘abc.jpg’,’這是水印文字’,’ziti.ttf’,30,0)

*/

class image_fu{

private $image;

private $img_info;

private $img_width;

private $img_height;

private $img_im;

private $img_text;

private $img_ttf=”;

private $img_new;

private $img_text_size;

private $img_jd;

function img($img=”,$txt=”,$ttf=”,$size=12,$jiaodu=0){

if(isset($img)file_exists($img)){//檢測圖片是否存在

$this-image =$img;

$this-img_text=$txt;

$this-img_text_size=$size;

$this-img_jd=$jiaodu;

if(file_exists($ttf)){

$this-img_ttf=$ttf;

}else{

exit(‘字體文件:’.$ttf.’不存在!’);

}

$this-imgyesno();

}else{

exit(‘圖片文件:’.$img.’不存在’);

}

}

private function imgyesno(){

$this-img_info =getimagesize($this-image);

$this-img_width =$this-img_info[0];//圖片寬

$this-img_height=$this-img_info[1];//圖片高

//檢測圖片類型

switch($this-img_info[2]){

case 1:$this-img_im = imagecreatefromgif($this-image);break;

case 2:$this-img_im = imagecreatefromjpeg($this-image);break;

case 3:$this-img_im = imagecreatefrompng($this-image);break;

default:exit(‘圖片格式不支持水印’);

}

$this-img_text();

}

private function img_text(){

imagealphablending($this-img_im,true);

//設定顏色

$color=imagecolorallocate($this-img_im,rand(0,255),rand(0,255),rand(0,255));

$txt_height=$this-img_text_size;

$txt_jiaodu=$this-img_jd;

$ttf_im=imagettfbbox($txt_height,$txt_jiaodu,$this-img_ttf,$this-img_text);

$w = $ttf_im[2] – $ttf_im[6];

$h = $ttf_im[3] – $ttf_im[7];

//$w = $ttf_im[7];

//$h = $ttf_im[8];

unset($ttf_im);

$txt_y =$this-img_height-$h;

$txt_x =$this-img_width-$w;

//$txt_y =0;

//$txt_x =0;

$this-img_new=@imagettftext($this-img_im,$txt_height,$txt_jiaodu,$txt_x,$txt_y,$color,$this-img_ttf,$this-img_text);

@unlink($this-image);//刪除圖片

switch($this-img_info[2]) {//取得背景圖片的格式

case 1:imagegif($this-img_im,$this-image);break;

case 2:imagejpeg($this-img_im,$this-image);break;

case 3:imagepng($this-img_im,$this-image);break;

default: exit(‘水印圖片失敗’);

}

}

//顯示圖片

function img_show(){echo ‘img src=”‘.$this-image.'” border=”0″ alt=”‘.$this-img_text.'” /’;}

//釋放內存

private function img_nothing(){

unset($this-img_info);

imagedestroy($this-img_im);

}

}

?

php如何給excel表格添加水印

1

首先打開excel界面,進入excel工作區

步驟閱讀

2

然後隨便選擇一個單元格,點擊選中

步驟閱讀

3

之後點擊工具欄上的“插入”按鈕,點擊“藝術字”選項

步驟閱讀

4

在彈出的藝術字選項列表中,選中一個藝術字,將其選中

步驟閱讀

5

然後就可以在文本框中輸入文字信息了,比如輸入涉密文字信息

步驟閱讀

6

點擊選中該藝術字,然後點擊右鍵,彈出的菜單項中,點擊“設置文本效果格式”,進入設置界面

步驟閱讀

7

點擊“文本填充”選項,選中純色填充,在顏色選擇框中,選擇一個灰色的顏色,然後將透明度根據情況進行設置,我們就能得到具有水印效果的excel文本了

步驟閱讀

步驟閱讀

END

PHP如何對上傳的圖片加水印?

這個要用到PHP的GD擴展,用這個擴展庫可以給圖片加水印。

參考一下這段代碼:

?php

/*

* 功能:PHP圖片水印 (水印支持圖片或文字)

* 參數:

* $groundImage 背景圖片,即需要加水印的圖片,暫只支持GIF,JPG,PNG格式;

* $waterPos 水印位置,有10種狀態,0為隨機位置;

* 1為頂端居左,2為頂端居中,3為頂端居右;

* 4為中部居左,5為中部居中,6為中部居右;

* 7為底端居左,8為底端居中,9為底端居右;

* $waterImage 圖片水印,即作為水印的圖片,暫只支持GIF,JPG,PNG格式;

* $waterText 文字水印,即把文字作為為水印,支持ASCII碼,不支持中文;

* $textFont 文字大小,值為1、2、3、4或5,默認為5;

* $textColor 文字顏色,值為十六進制顏色值,默認為#FF0000(紅色);

*

* 注意:Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG

* $waterImage 和 $waterText 最好不要同時使用,選其中之一即可,優先使用 $waterImage。

* 當$waterImage有效時,參數$waterString、$stringFont、$stringColor均不生效。

* 加水印後的圖片的文件名和 $groundImage 一樣。

* 作者:longware @ 2004-11-3 14:15:13

*/

function imageWaterMark($groundImage,$waterPos=0,$waterImage=””,$waterText=””,$textFont=5,$textColor=”#FF0000″)

{

$isWaterImage = FALSE;

$formatMsg = “暫不支持該文件格式,請用圖片處理軟件將圖片轉換為GIF、JPG、PNG格式。”;

//讀取水印文件

if(!emptyempty($waterImage) file_exists($waterImage))

{

$isWaterImage = TRUE;

$water_info = getimagesize($waterImage);

$water_w = $water_info[0];//取得水印圖片的寬

$water_h = $water_info[1];//取得水印圖片的高

switch($water_info[2])//取得水印圖片的格式

{

case 1:$water_im = imagecreatefromgif($waterImage);break;

case 2:$water_im = imagecreatefromjpeg($waterImage);break;

case 3:$water_im = imagecreatefrompng($waterImage);break;

default:die($formatMsg);

}

}

//讀取背景圖片

if(!emptyempty($groundImage) file_exists($groundImage))

{

$ground_info = getimagesize($groundImage);

$ground_w = $ground_info[0];//取得背景圖片的寬

$ground_h = $ground_info[1];//取得背景圖片的高

switch($ground_info[2])//取得背景圖片的格式

{

case 1:$ground_im = imagecreatefromgif($groundImage);break;

case 2:$ground_im = imagecreatefromjpeg($groundImage);break;

case 3:$ground_im = imagecreatefrompng($groundImage);break;

default:die($formatMsg);

}

}

else

{

die(”需要加水印的圖片不存在!”);

}

//水印位置

if($isWaterImage)//圖片水印

{

$w = $water_w;

$h = $water_h;

$label = “圖片的”;

}

else//文字水印

{

$temp = imagettfbbox(ceil($textFont*5),0,”./cour.ttf”,$waterText);//取得使用 TrueType 字體的文本的範圍

$w = $temp[2] – $temp[6];

$h = $temp[3] – $temp[7];

unset($temp);

$label = “文字區域”;

}

if( ($ground_w$w) || ($ground_h$h) )

{

echo “需要加水印的圖片的長度或寬度比水印”.$label.”還小,無法生成水印!”;

return;

}

switch($waterPos)

{

case 0://隨機

$posX = rand(0,($ground_w – $w));

$posY = rand(0,($ground_h – $h));

break;

case 1://1為頂端居左

$posX = 0;

$posY = 0;

break;

case 2://2為頂端居中

$posX = ($ground_w – $w) / 2;

$posY = 0;

break;

case 3://3為頂端居右

$posX = $ground_w – $w;

$posY = 0;

break;

case 4://4為中部居左

$posX = 0;

$posY = ($ground_h – $h) / 2;

break;

case 5://5為中部居中

$posX = ($ground_w – $w) / 2;

$posY = ($ground_h – $h) / 2;

break;

case 6://6為中部居右

$posX = $ground_w – $w;

$posY = ($ground_h – $h) / 2;

break;

case 7://7為底端居左

$posX = 0;

$posY = $ground_h – $h;

break;

case 8://8為底端居中

$posX = ($ground_w – $w) / 2;

$posY = $ground_h – $h;

break;

case 9://9為底端居右

$posX = $ground_w – $w;

$posY = $ground_h – $h;

break;

default://隨機

$posX = rand(0,($ground_w – $w));

$posY = rand(0,($ground_h – $h));

break;

}

//設定圖像的混色模式

imagealphablending($ground_im, true);

if($isWaterImage)//圖片水印

{

imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷貝水印到目標文件

}

else//文字水印

{

if( !emptyempty($textColor) (strlen($textColor)==7) )

{

$R = hexdec(substr($textColor,1,2));

$G = hexdec(substr($textColor,3,2));

$B = hexdec(substr($textColor,5));

}

else

{

die(”水印文字顏色格式不正確!”);

}

imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));

}

//生成水印後的圖片

@unlink($groundImage);

switch($ground_info[2])//取得背景圖片的格式

{

case 1:imagegif($ground_im,$groundImage);break;

case 2:imagejpeg($ground_im,$groundImage);break;

case 3:imagepng($ground_im,$groundImage);break;

default:die($errorMsg);

}

//釋放內存

if(isset($water_info)) unset($water_info);

if(isset($water_im)) imagedestroy($water_im);

unset($ground_info);

imagedestroy($ground_im);

}

//—————————————————————————————

$id=$_REQUEST[‘id’];

$num = count($_FILES[‘userfile’][‘name’]);

print_r($_FILES[‘userfile’]);

print_r($_FILES[‘userfile’][‘name’]);

echo $num;

echo “bR”;

if(isset($id)){

for($i=0;$i$id;$i++){

if(isset($_FILES) !emptyempty($_FILES[‘userfile’]) $_FILES[‘userfile’][‘size’]0)

{

$uploadfile = “./”.time().”_”.$_FILES[‘userfile’][name][$i];

echo “br”;

echo $uploadfile;

if (copy($_FILES[‘userfile’][‘tmp_name’][$i], $uploadfile))

{

echo “OKbr”;

//文字水印

//imageWaterMark($uploadfile,5,””,”” target=”_blank””,5,”#cccccc“);

//圖片水印

$waterImage=”logo_ok1.gif”;//水印圖片路徑

imageWaterMark($uploadfile,9,$waterImage);

echo “img src=\””.$uploadfile.”\” border=\”0\””;

}

else

{

echo “Failbr”;

}

}

}

}

?

form enctype=”multipart/form-data” method=”POST”

?php

for($a=0;$a$id;$a++){

echo “文件: input name=\”userfile[]\” type=\”file\”br”;

}

?

input type=”submit” value=”上傳”

/form

原創文章,作者:WOAP,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/133277.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
WOAP的頭像WOAP
上一篇 2024-10-03 23:57
下一篇 2024-10-03 23:57

相關推薦

  • Python飛機大戰中文字資源分析

    Python飛機大戰是一款經典的飛行射擊遊戲,在遊戲過程中,玩家需要控制一架飛機不斷消滅敵人,生存到最後。該遊戲使用Python語言編寫,其中涉及到的文字資源對遊戲的整體體驗有重要…

    編程 2025-04-29
  • 使用Spire.PDF進行PDF文檔處理

    Spire.PDF是一款C#的PDF庫,它可以幫助開發者快速、簡便地處理PDF文檔。本篇文章將會介紹Spire.PDF庫的一些基本用法和常見功能。 一、PDF文檔創建 創建PDF文…

    編程 2025-04-29
  • Python七年級內容用法介紹

    本文將從多個方面對Python七年級內容進行詳細闡述。 一、安裝Python 要使用Python進行編程,首先需要在計算機上安裝Python。Python可以在官網上免費下載。下載…

    編程 2025-04-29
  • Python如何打出精美文字

    Python作為一種高級編程語言,擁有廣泛的應用領域。其中最常見的一項應用就是文字處理。Python可以幫助我們打出各種類型的文字,從簡單的文本到複雜的圖形和音頻文件都不在話下。 …

    編程 2025-04-28
  • Python爬蟲文檔報告

    本文將從多個方面介紹Python爬蟲文檔的相關內容,包括:爬蟲基礎知識、爬蟲框架及常用庫、爬蟲實戰等。 一、爬蟲基礎知識 1、爬蟲的定義: 爬蟲是一種自動化程序,通過模擬人的行為在…

    編程 2025-04-28
  • Python定位文字的實現方法

    本文將從多個方面對Python定位文字進行詳細的闡述,包括字符串匹配、正則表達式和第三方庫等方面。 一、字符串匹配 字符串匹配是最基礎的Python定位文字方法,適用於簡單的字符串…

    編程 2025-04-28
  • Python獲取Flutter上內容的方法及操作

    本文將從以下幾個方面介紹Python如何獲取Flutter上的內容: 一、獲取Flutter應用數據 使用Flutter提供的Platform Channel API可以很容易地獲…

    編程 2025-04-28
  • 使用Python繪圖時如何添加文字

    在Python中繪圖是一種十分重要的數據可視化方式,而其中添加文字則是讓圖像更加生動、信息更加詳細的重要手段。本篇文章可以幫助您學習如何在繪圖中添加文字。在代碼中,我們將使用mat…

    編程 2025-04-28
  • Python少兒編程的學習內容

    Python被譽為是最適合新手入門的編程語言之一,它簡潔易懂,同時涵蓋了廣泛的編程知識。Python的少兒編程課程也因其易學性和實用性越來越受到家長和孩子們的歡迎。接下來我們將從多…

    編程 2025-04-28
  • Python生成PDF文檔

    Python是一門廣泛使用的高級編程語言,它可以應用於各種領域,包括Web開發、數據分析、人工智能等。在這些領域的應用中,有很多需要生成PDF文檔的需求。Python有很多第三方庫…

    編程 2025-04-28

發表回復

登錄後才能評論