導航:首頁 > 編程語言 > php圖片水印

php圖片水印

發布時間:2022-01-24 12:59:16

php文字水印,水印會根據圖片的大小自動變化

這個好像有點復雜哦
一般水印都是用GD庫函數實現的,你可以把上傳的圖片長寬取出來,這應該不難吧,然後根據需要在你實現水印的函數里根長寬參數關聯,應該就能實現。

Ⅱ PHP給圖片加水印的思想是什麼

貼個php的圖片處理類 你可以自己研究下 共同進步 呵呵

/*
此類包含以下功能
A.生成縮略圖
B.給圖片添加文字水印(包括中文)
C.將指定的圖片旋轉90度/180度/270度,並保存至文件
D.將圖片水平/垂直翻轉,並保存至文件
E.在線裁剪圖片任意部分矩形(正在編寫之中)
具體目標效果暫時可以參考 http://yananzb.com/cut/cut.htm
期待您的響應

成員函數說明
---------------------------------------------------------------------------------------------
public void CImage::__construct(string $src_image_file)
功能:類CImage的構造函數
參數
$src_image_file 字元串,源圖片文件名 注意,目前只支持gif,png,jpeg,jpg格式,這是GD庫的限制,並非本程序的局限
---------------------------------------------------------------------------------------------
public bool CImage: thumb($image_dist,$x)
功能:根據源圖片生成縮略圖,並保存至文件
$image_dist 字元串 目標縮略圖片路徑及文件名 如 /File/th.jpg
$x 整型 目標縮略圖片的尺寸限制即當原始圖片的寬大於高時,那麼新的縮略圖的寬為$x,反之高為$x
---------------------------------------------------------------------------------------------
public bool image_press($image_dist,$str,$font="simkai.ttf")

函數功能:
圖片生成水印並保存新圖片至目標文件
參數說明:
$image_dist 字元串 目標圖片名
$str 字元串 要寫入到圖片水印的字元串
$font 字元串 合法的系統字體名或WEB目錄中正確的字體文件名
---------------------------------------------------------------------------------------------
public bool rotate($image_dist,$angle)
函數功能:
將源圖片旋轉一定角度並將新圖片保存至文件
參數說明:
$image_dist 字元串 目標圖片文件名
$angle 整數 要旋轉的角度 只能是90或180或270度
---------------------------------------------------------------------------------------------
public bool rotate_h($image_dist)
函數功能:
將源圖片水平翻轉,並將新圖片保存至文件
參數說明:
$image_dist 字元串 目標圖片文件名
---------------------------------------------------------------------------------------------
public bool rotate_v($image_dist)
函數功能:
將源圖片垂直翻轉,並將新圖片保存至文件
參數說明:
$image_dist 字元串 目標圖片文件名
---------------------------------------------------------------------------------------------
使用範例:
$p=new CImage("s.jpg"); //創建一個圖片處理對象
$p->thumb("thumb.jpg",300); //生成縮略圖 限制尺寸為300,保存為thumb.jpg
$p->rotate("rt.jpg",90); //旋轉90度,並保存為rt.jpg,類似地,你可以將90換成180,270進行旋轉
$p->rotate_h("h.jpg"); //水平翻轉
$p->rotate_v("v.jpg"); //垂直翻轉

*/
class CImage{
var $src_image;
var $width;
var $height;
var $image_type;
var $img;
var $src_x;
var $src_y;

function __construct($image_file)
{
$info=GetImageSize($image_file);
$this->src_image=$image_file;
$this->width=$info[0];
$this->height=$info[1];

switch($info[2])
{
case 1:
$this->image_type="gif";
break;
case 2:
$this->image_type="jpeg";
break;
case 3:
$this->image_type="png";
break;
default:
return false;
//echo("Unsurport Image type.");
break;
} //swith end
//echo "ok";
$new_function='ImageCreateFrom'.ucfirst($this->image_type);
$this->img=$new_function($this->src_image);
$this->src_x=ImageSX($this->img);
$this->src_y=ImageSY($this->img);
}
function thumb($image_dist,$x) //$x為新圖的限制邊的尺寸
{
$src_x=ImageSX($this->img);
$src_y=ImageSY($this->img);
$scale=min($x/$src_x,$x/$src_y);

if($scale<1)
{
$new_x=floor($scale*$src_x);
$new_y=floor($scale*$src_y);
$img_tmp=ImageCreateTrueColor($new_x,$new_y); //set the size of Canvas for the new Image
ImageCopyResampled($img_tmp,$this->img,0,0,0,0,$new_x,$new_y,$src_x,$src_y); //Resampled
ImageDestroy($this->img);
$new_function="Image".ucfirst($this->image_type);

return $new_function($img_tmp,$image_dist);
}
} // thumb end

//給圖片生成文字水印
function image_press($image_dist,$str,$font="simkai.ttf") {
$str=iconv("GB2312","utf-8",$str);
$blue=ImageColorAllocate($this->img,90,255,255);
$white=ImageColorAllocate($this->img,255,0,0);
ImageTTFText($this->img,20,0,$this->src_x/2/2,$this->src_y-80,$white,$font,$str);
$new_function="Image".ucfirst($this->image_type);
return $new_function($this->img,$image_dist);
}

function rotate($image_dist,$angle)
{
$img_tmp=null;
$new_function="Image".ucfirst($this->image_type);
if(($angle!=90)&&($angle!=180)&&($angle!=270))
{
echo("Un-valid angle on calling CImage::rotate(\$image_dist,\$angle) .<p>The valid angle must be 90 or 180 or 270.");
return false;
}

if(($angle==90)||($angle==270))
{
$img_tmp=ImageCreateTrueColor($this->src_y,$this->src_x);
}
else
{
$img_tmp=ImageCreateTrueColor($this->src_x,$this->src_y);
}

switch($angle)
{
case 90:
for($i=0;$i<$this->src_x;$i++)
{
for($j=0;$j<$this->src_y;$j++)
{
ImageSetPixel($img_tmp,$this->src_y-$j-1,$i,ImageColorAt($this->img,$i,$j));
}
}
return $new_function($img_tmp,$image_dist);
break;

case 180:
for($i=0;$i<$this->src_x;$i++)
{
for($j=0;$j<$this->src_y;$j++)
{
ImageSetPixel($img_tmp,$this->src_x-$i-1,$this->src_y-$j-1,ImageColorAt($this->img,$i,$j));
}
}
return $new_function($img_tmp,$image_dist);
break;

case 270:
for($i=0;$i<$this->src_x;$i++)
{
for($j=0;$j<$this->src_y;$j++)
{
ImageSetPixel($img_tmp,$j,$this->src_x-$i-1,ImageColorAt($this->img,$i,$j));
}
}
return $new_function($img_tmp,$image_dist);
break;
} //end switch

} //end rotate

function rotate_h($image_dist)
{
$new_function="Image".ucfirst($this->image_type);
$img_tmp=ImageCreateTrueColor($this->src_x,$this->src_y);
ImageCopyResampled($img_tmp,$this->img,0,0,$this->src_x-1,0,$this->src_x,$this->src_y,-$this->src_x,$this->src_y); //水平翻轉
return $new_function($img_tmp,$image_dist);
}

function rotate_v($image_dist)
{
$new_function="Image".ucfirst($this->image_type);
$img_tmp=ImageCreateTrueColor($this->src_x,$this->src_y);
ImageCopyResampled($img_tmp,$this->img,0,0,0,$this->src_y-1,$this->src_x,$this->src_y,$this->src_x,-$this->src_y);
return $new_function($img_tmp,$image_dist);
}
} //end CImage

Ⅲ php 如何檢查圖片是否已經加過水印 求解

在php採集的時候,尤其是大量的自動採集的時候,加了水印的圖片想程序自動鑒別。
你是這種想法嗎?
這種想法可以,但沒有這種方法。以前沒有,今後也不會有。
水印和圖片已經形成一張新圖片了,不要說PHP對圖片沒有識別能力,就算PHP對圖片有識別能力,它也沒有辦法識別圖片上哪個屬於圖片內容,哪個屬於水印內容。
但是,我們就沒有辦法處理水印的問題嗎?辦法肯定是有的。我提供幾種思路:
1、我們自己建立一個無水印網站地址庫,這個由我們日常來管理。php通過圖片的真實地址,屬於無水印網站地址范圍,就認為是無水印的。不在范圍內的,就作為有水印處理。
2、如果我們固定從某個大站取圖片,它的圖片有的有水印,有的無水印,而且有水印的都是那麼固定的格式,那我們就根據它的方法,在水印上添加我們的水印。但這不是萬能的,如果它在圖片上全部鋪滿它的logo或者網址,像貼滿膏葯一樣無法下手,我們只能對此說sorry,換個網站吧。

Ⅳ php添加文字和圖片水印問題。

//可能是你的編碼設置有問題,在配置文件中設置編碼為UTF-8或者別的,反正和你其它地方編碼統一
header('Content-Type:text/html;charset=utf-8');

Ⅳ 用PHP代碼給圖片加水印

這篇文章主要介紹了用PHP代碼給圖片加水印的相關資料,需要的朋友可以參考下
先找好一張圖片,更名為face.jpeg,創建watermark.php:
?
1
2
3
4
5
6
7
8
9
10
11
12
<?php
/**
*
Created
by
PhpStorm.
*
User:
Administrator
*
Date:
2015/6/29
*
Time:
22:27
*/
$img
=
imagecreatefromjpeg('face.jpeg');//根據已有的JPG創建image
header('Content-type:image/jpeg');//設置mime
type
imagestring($img,5,5,5,'Vito-L',imagecolorallocate($img,255,0,0));//生成水印,imagestring(圖片,字體,位置x,位置y,字元串,顏色)
imagejpeg($img);//輸出圖片
//整幅圖像的左上角為
0,0
效果如下:
以上所述就是本文的全部內容了,希望大家能夠喜歡。

Ⅵ 請問php怎麼去除採集到的圖片水印,怎麼去除水印呢,求解

PHP去除水印需要用插件在線處理,這種方法是不可取的。
推薦方法:使用PS等圖片處理工具進行處理。

Ⅶ PHP給圖片添加文字水印

請確認C:\WINDOWS\Fonts\simkai.ttf';是否支持中文
或不要轉換
$str = iconv('GB2312','UTF-8',$str);
直接
$str=$str;

Ⅷ 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)//圖片水印
{
image($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 (($_FILES['userfile']['tmp_name'][$i], $uploadfile))
{
echo 「OK<br>」;
//文字水印
//imageWaterMark($uploadfile,5,」",」www.lvye.info" target="_blank">http://www.lvye.info」,5,」#cccccc「);
//圖片水印
$waterImage=」logo_ok1.gif」;//水印圖片路徑
imageWaterMark($uploadfile,9,$waterImage);
echo 「<img src=\」".$uploadfile.」\」 border=\」0\」>」;
}
else
{
echo 「Fail<br>」;
}
}
}
}
?>
<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>

Ⅸ php代碼 可以直接去掉圖片水印嗎怎樣去

使用PHP代碼只能生成圖片水印,想要去掉圖片水印要藉助PS等工具,不過很麻煩

Ⅹ 去圖片水印PHP代碼

這個一般手工操作,因為水印大小,位置都不同,如果你可以確認位置和用什麼覆蓋(若水印蓋住圖片細節,怎麼覆蓋),那才有編程解決的可能。
老老實實用ps吧,需要比較多的勞動力的事

閱讀全文

與php圖片水印相關的資料

熱點內容
安卓如何查看異常重啟 瀏覽:715
解壓音樂排名 瀏覽:383
安卓手機瀏覽器怎麼掃二維碼 瀏覽:715
通達信成本均線源碼 瀏覽:614
可以下載的解壓音頻 瀏覽:564
海賊王怎麼換伺服器 瀏覽:318
計算機上的共享文件夾映射 瀏覽:940
榮耀安裝包在文件夾哪裡 瀏覽:195
機票php源碼 瀏覽:231
linux共享mac 瀏覽:922
中國沒有國外的伺服器地址 瀏覽:759
為什麼退款伺服器連接錯誤 瀏覽:557
android簡訊存儲位置 瀏覽:972
unix網路編程卷4 瀏覽:808
找靚機app下單什麼時候發貨 瀏覽:413
android一個應用兩個進程 瀏覽:803
linux硬碟復制 瀏覽:808
php圖片伺服器搭建 瀏覽:801
下載壓縮文件怎麼打開 瀏覽:194
新建文件夾叫什麼名字 瀏覽:567