導航:首頁 > 編程語言 > php加水印保存

php加水印保存

發布時間:2023-03-24 22:02:50

A. php給圖片添加文字水印

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

B. 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

C. imagefttext生成水印怎麼保存 php的

使用imagepng()/imagejpeg()/imagegif()函數;
使用這幾個函數時添加第二個參數(你想保存的圖片完整路徑),它就會根據這個路徑生成圖片文件並且保存到該路徑下。比如:
$im=imagecreatefrompng("1.png"); //取出原圖
$hb=imagecolorallocate($im,0,0,0);
imagettftext($im,50,0,40,150,$hb,"STXINGKA.TTF","兄弟連lamp156"); //加水印
imagepng($im,"images/water1.png"); //保存水印圖到本文件夾下images文件夾,水印圖命名為water1.png
imagedestroy($im);
//由於是保存圖片而非顯示圖片,所以header("content-type:image/png");是不需要的

D. php 怎麼上傳完圖片之後,給這個圖片打水印,並且保存在另一個文件夾

這個php中的圖片處理類完全足夠了,使用圖片水印

$groundImg = "DSC05940.jpeg";
$groundInfo = getimagesize($groundImg);
$ground_w = $groundInfo[0];
//print_r($groundInfo);
$ground_h = $groundInfo[1];
switch($groundInfo[2]){
case 1:
$ground_im = imagecreatefromgif($groundImg);
break;
case 2:
$ground_im = imagecreatefromjpeg($groundImg);
break;
case 3:
$ground_im = imagecreatefrompng($groundImg);
break;
}

$waterImg = "DSC05949.jpeg";
$imgInfo =getimagesize($waterImg);
$water_w = $imgInfo[0];
$water_w = $imgInfo[1];

switch($imgInfo[2]){
case 1:
$water_im = imagecreatefromgif($waterImg);
break;
case 2:
$water_im = imagecreatefromjpeg($waterImg);
break;
case 3:
$water_im = imagecreatefrompng($waterImg);
break;
}
image($ground_im,$water_im,100,100,0,0,500,500);
header("Content-type: image/jpeg");

imagejpeg($ground_im);

這些都很麻煩,建議使用框架,很多框架都提供了圖片處理類供使用

E. php如何實現自動加水印

加水印邏輯有兩種

一種是上傳直接加水印

另一種是利用偽靜態將圖片訪問重定向到處理程序,臨時加水印緩存並輸出

php處理圖片加水印可以使用gd庫中的相關函數

以下為臨時手打代碼,可以按此思路優化,有問題可以聯系本人

//此處需根據上傳的圖片格式使用對應函數實例化圖片
$img=imagecreatefromjpg($imgurl);
//根據水印圖片路徑實例化水印
$waterImg=imagecreatefrompng($waterpath);
//獲取原圖及水印圖片尺寸,用以計算是否需要縮放及放置位置
list($width,$height,$type,$attr)=getimagesize($imgurl);
list($waterw,$waterh,$type,$attr)=getimagesize($waterpath);
$scale=1;
$waterReleaseW=$waterw;
$waterReleaseH=$waterh;
if($waterReleaseW>$width*.5){
$scale=$width*.5/$waterw;
$waterReleaseW=$width*.5;
$waterReleaseH=$waterh*$scale;
}
if($waterReleaseH>$height*.5){
$scale*=$height*.5/$waterh;
$waterReleaseH=$height*.5;
$waterReleaseW=$waterw*$scale;
}

//將水印圖片拷貝到原圖指定位置(此示例為右下角)
imageresized($img,$waterImg,
$width-$waterReleaseW-10,$height-$waterReleaseH-10,
0,0,
$width-10,$height-10,
$waterw,$waterh);
//銷毀水印圖片實例
imagedestroy($waterImg);

//水印後圖片保存
imagejpeg($img,$newpath);

F. 怎麼給php 網站視頻添加水印

通過php調用ffmpeg命令加水印!

G. php 給圖片添加文字或圖片 並實現保存,,急救!!

簡單說,這就是PHP的一個生成水印的功能了。
直接帖代碼給你。並附上注釋吧,應該能看懂。

<?php
header("Content-type: image/jpeg");    //瀏覽器輸出,如不需要可去掉此行
$im = @imagecreatefromjpeg('test.jpg');    //從圖片建立文件,此處以jpg文件格式為例
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
$text = 'Testing...'; //要寫到圖上的文字
$font = 'arial.ttf'; //寫的文字用到的字體。
$srcw=imagesx($im);
imagettftext($im, 20, 0, $srcw-210, 21, $grey, $font, $text);
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagettftext($im, 20, 0, 9, 19, $white, $font, $text);
imagepng($im);
imagedestroy($im);
?>

閱讀全文

與php加水印保存相關的資料

熱點內容
盲人賣花女 然後賺錢治好她的眼睛的電影吳孟達 瀏覽:683
編譯程序有哪些用 瀏覽:945
變身之後我與她的狂想曲txt 瀏覽:843
睡在我上下前後左右鋪的兄弟閱讀 瀏覽:531
搜編程課程入口 瀏覽:226
韓國拍的朝鮮戰爭電影有哪些 瀏覽:262
裕泉影視台灣電影 瀏覽:35
安卓怎麼激活電源 瀏覽:519
推油類電影 瀏覽:112
好的看片網站 瀏覽:982
人吃人食人族電影全集 瀏覽:729
0855最新網址 瀏覽:4
浪潮伺服器如何安裝raid1 瀏覽:757
exe程序反向編譯工具 瀏覽:470
亞瑟的電影叫什麼名字 瀏覽:826
javaimport找不到 瀏覽:730
德銀投資加密貨幣 瀏覽:565
編譯器的前端包括什麼 瀏覽:379
宅男小電影在線 瀏覽:95
西班牙露奶電影有哪些? 瀏覽:691