本文目錄一覽:
用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給圖片添加文字水印
請確認C:\WINDOWS\Fonts\simkai.ttf’;是否支持中文
或不要轉換
$str = iconv(‘GB2312′,’UTF-8’,$str);
直接
$str=$str;
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;
}
//將水印圖片拷貝到原圖指定位置(此示例為右下角)
imagecopyresized($img,$waterImg,
$width-$waterReleaseW-10,$height-$waterReleaseH-10,
0,0,
$width-10,$height-10,
$waterw,$waterh);
//銷毀水印圖片實例
imagedestroy($waterImg);
//水印後圖片保存
imagejpeg($img,$newpath);
php如何給圖片加文字水印
我知道的有三種,都是使用GD庫的image函數
一種是直接在圖片上寫文字
imagefttext();
一種是帶透明度的水印圖片
imagecopy();
還有一種是可以自定義水印圖片透明度的
imagecopymerge();
你想要什麼效果,可以接著細說
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/151340.html