注釋非常的詳細了,這里就不多廢話了
<?php
/*給圖片加文字水印的方法*/
$dst_path = 'http://f4.topitme.com/4/15/11/1166351597fe111154l.jpg';
$dst = imagecreatefromstring(file_get_contents($dst_path));
/*imagecreatefromstring()--從字符串中的圖像流新建一個圖像,返回一個圖像標示符,其表達了從給定字符串得來的圖像
圖像格式將自動監(jiān)測,只要php支持jpeg,png,gif,wbmp,gd2.*/
$font = './t1.ttf';
$black = imagecolorallocate($dst, 0, 0, 0);
imagefttext($dst, 20, 0, 10, 30, $black, $font, 'Hello world!');
/*imagefttext($img,$size,$angle,$x,$y,$color,$fontfile,$text)
$img由圖像創(chuàng)建函數(shù)返回的圖像資源
size要使用的水印的字體大小
angle(角度)文字的傾斜角度,如果是0度代表文字從左往右,如果是90度代表從上往下
x,y水印文字的第一個文字的起始位置
color是水印文字的顏色
fontfile,你希望使用truetype字體的路徑*/
list($dst_w,$dst_h,$dst_type) = getimagesize($dst_path);
/*list(mixed $varname[,mixed $......])--把數(shù)組中的值賦給一些變量
像array()一樣,這不是真正的函數(shù),而是語言結(jié)構(gòu),List()用一步操作給一組變量進行賦值*/
/*getimagesize()能獲取到什么信息?
getimagesize函數(shù)會返回圖像的所有信息,包括大小,類型等等*/
switch($dst_type){
case 1://GIF
header("content-type:image/gif");
imagegif($dst);
break;
case 2://JPG
header("content-type:image/jpeg");
imagejpeg($dst);
break;
case 3://PNG
header("content-type:image/png");
imagepng($dst);
break;
default:
break;
/*imagepng--以PNG格式將圖像輸出到瀏覽器或文件
imagepng()將GD圖像流(image)以png格式輸出到標注輸出(通常為瀏覽器),或者如果用filename給出了文件名則將其輸出到文件*/
}
imagedestroy($dst);
?>
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
新聞熱點
疑難解答
圖片精選