php 給圖片加上文字浮水印代碼

來源:互聯網
上載者:User
 代碼如下 複製代碼

$image=$_get[id];
$im=getimagesize($image);
//print_r($im);
//以下是讀取文字的寬高
$font='verdana.ttf';//字型
$font_size = $im[0]/20;//文字大小
$size=imagettfbbox($font_size,0,$font,'111cn.net');//文字寬高
$textwidth = $size [4];//取出寬
$textheight = abs( $size [7] );//取出高

$pic_w=abs(($im[0]-$textwidth)/2);//文字存放寬的位置
$pic_h=abs(($im[1]-$textheight)/2);//文字存放高的位置

 switch($im[2])               
{
case 1:
$im=imagecreatefromgif($image);
break;

case 2:
$im=imagecreatefromjpeg($image);
break;

case 3:
$im=imagecreatefrompng($image);
break;
}
//$logo="2.png";//商標圖片
//$ing=getimagesize($logo);
//
// switch($ing[2])               
//
//{
//case 1:
//$in=imagecreatefromgif($logo);
//break;
//
//case 2:
//$in=imagecreatefromjpeg($logo);
//break;
//
//case 3:
//$in=imagecreatefrompng($logo);
//break;
//}
//imagecopy($im,$in,200,3,0,0,'120','110');//圖片合并
 $te = imagecolorclosestalpha($im,255,255,255,60);//最後一個數值是透明度越大越透明
$str=iconv("gbk","utf-8","111cn.net"); //設定文字的內容和編碼,很簡單吧

imagettftext($im,$font_size,0,$pic_w,$pic_h,$te,'verdana.ttf',$str);

header("content-type: image/jpeg");
imagejpeg($im);


?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.