1. 程式人生 > >php二維碼/26行程式碼製作php二維碼phpqrcode加grafika水印

php二維碼/26行程式碼製作php二維碼phpqrcode加grafika水印

歡迎大家加入討論 q裙827880170


用到的外掛有phpqrcode(二維碼的生成庫,自行百度)
grafika(非常好用的圖片處理庫,自行百度)

```
require_once "phpqrcode/phpqrcode.php";
require_once 'grafika/src/autoloader.php';
$editor = \Grafika\Grafika::createEditor(); //例項化
$object = new \QRcode();
$logo_path = 'images/qr_logo_s.png';//logo地址
$diban_path = 'images/qr_diban_s.png';//背景圖
$qr_tmp_path = 'images/tmp_qr.png';//二維碼生成的臨時二維碼
$qr_tmp_path2 = 'images/tmp_qr2.png';//二維碼生成的臨時二維碼
$qr_url = 'images/qr.png';//最終生成二維碼
$value = 'http://233.1231231231231231231231231231231.222'; //二維碼內容,如果是網址最好加上http://||https://(V
vx掃描可以直接出網址)
$water = 'No.123456';
$errorCorrectionLevel = 'H';//容錯級別
$matrixPointSize = 3.7;//生成圖片大小
$matrixMarginSize = 2;//邊距大小
$object::png($value,$qr_tmp_path, $errorCorrectionLevel, $matrixPointSize, $matrixMarginSize);
$editor->open($image1 , $qr_tmp_path );
$editor->open( $image2 , $logo_path);
$editor->blend ( $image1, $image2 , 'normal', 1, 'top-left',72,71);//位置需要根據自己的專案自行調整
$editor->save($image1,$qr_tmp_path2);
$editor->open($image3 , $diban_path);
$editor->open($image4 ,$qr_tmp_path2 );
$editor->blend ( $image3, $image4 , 'normal', 1, 'top-left',32.5,54);//位置需要根據自己的專案自行調整
$editor->text($image3 ,$water,11,89.5,260,new \Grafika\Color("#ffffff"));//加入水印
$editor->save($image3,$qr_url);
unlink($qr_tmp_path);//銷燬圖片
unlink($qr_tmp_path2);//銷燬圖片
```


最終生成的效果圖如下啦~~