国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

個性化自己的二維碼

2019-11-15 01:43:59
字體:
供稿:網(wǎng)友
個性化自己的二維碼

一、什么是二維碼

二、我們?nèi)绾沃谱鞫S碼

三、如何制作自己的個性二維碼

1、第一步。下載php類庫phpqrcode,(附下載地址:http://sourceforge.net/PRojects/phpqrcode/)

網(wǎng)上給出的使用案列是:

<?php/*$errorCorrectionLevel 糾錯級別:L、M、Q、H  $matrixPointSize表示圖片每個黑點的像素點的大小:1到10  */include '/phpqrcode/phpqrcode.php';//引入PHP QR庫文件$value="個性化自己的二維碼";// 二維碼數(shù)據(jù) $errorCorrectionLevel = "l";// 糾錯級別:L、M、Q、H $matrixPointSize = "10";// 點的大小:1到10  QRcode::png($value, false, $errorCorrectionLevel);exit;?>

2、看懂上面的代碼

上面那段代碼發(fā)生了什么奇妙的旅程呢?

讓我么打開phpqrcode.php看一看,代碼太長了,就不貼了,各位自己下載去吧。

結(jié)合上面的代碼和phpqrcode.php,看一看:

<?php/*$errorCorrectionLevel 糾錯級別:L、M、Q、H  $matrixPointSize表示圖片每個黑點的像素點的大小:1到10  */include 'phpqrcode/phpqrcode.php';//引入PHP QR庫文件$intext="個性化自己的二維碼";// 二維碼數(shù)據(jù) $errorCorrectionLevel = "l";// 糾錯級別:L、M、Q、H $matrixPointSize = "2";// 點的大小:1到10  $margin = 1;$size = 10;$outfile = false;$saveandprint=false;$enc = QRencode::factory($errorCorrectionLevel, $size, $margin);//$enc->encodePNG($value, false, $saveandprint=false);try {ob_start();$tab = $enc->encode($intext);print_r($tab);$err = ob_get_contents();ob_end_clean();if ($err != '')QRtools::log($outfile, $err);/*標(biāo)記*/$maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$enc->margin));QRimage::png($tab, $outfile, min(max(1, $enc->size), $maxSize), $enc->margin,$saveandprint);} catch (Exception $e) {QRtools::log($outfile, $e->getMessage());}exit;?>

我們可以發(fā)現(xiàn),php類庫phpqrcode首先通過一種算法將我們需要的文字轉(zhuǎn)化為數(shù)組$tab ,然后通過圖像操作畫了一張圖片,也就是我們的二維碼。

如果打印數(shù)組$tab,就會發(fā)現(xiàn)他就是這樣的:

Array(    [0] => 1111111010101001001111111    [1] => 1000001001111001001000001    [2] => 1011101011100001101011101    [3] => 1011101011101110101011101    [4] => 1011101010011010001011101    [5] => 1000001000110111001000001    [6] => 1111111010101010101111111    [7] => 0000000000101111100000000    [8] => 1111001010110000110011101    [9] => 1010100010101110100111100    [10] => 1011011111111111111000111    [11] => 0010010011100000100001000    [12] => 0101111111101001100101100    [13] => 0100010111010111010001001    [14] => 0110101010110111010100001    [15] => 1001110110101100110111101    [16] => 0000101100110100111110000    [17] => 0000000011110101100010101    [18] => 1111111001010110101011010    [19] => 1000001001101100100010101    [20] => 1011101001100001111110001    [21] => 1011101010010110000000011    [22] => 1011101011000111011001110    [23] => 1000001011001010001001000    [24] => 1111111011000100100101111)

好吧,你懂了嗎&hellip;………

現(xiàn)在就簡單了,根據(jù)數(shù)組$tab,畫畫就可以了:

QRimage::png($tab, $outfile, min(max(1, $enc->size), $maxSize), $enc->margin,$saveandprint);

3、如何畫畫

如果我們?nèi)巳搜芯?a >源碼,會發(fā)現(xiàn)最關(guān)鍵的是這樣一個方法:

private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4);

下面貼出我注釋過的源碼(原類庫是沒有注釋的)

<?phpfunction image($frame, $pixelPerPoint = 4, $outerFrame = 4){//$frame就是數(shù)組$tab,$pixelPerPoint,$outerFrame現(xiàn)在看不出來是什么,待會解釋$h = count($frame);$w = strlen($frame[0]);//計算應(yīng)該畫多長多寬的畫,$h表示高,$w表示寬$imgW = $w + 2*$outerFrame;$imgH = $h + 2*$outerFrame;//它把畫布變大了一點!說明$outerFrame是周圍留白大小$base_image =ImageCreate($imgW, $imgH);//imagecreate — 新建一個基于調(diào)色板的圖像,換句話說,我們現(xiàn)在可以基于$base_image畫畫了$col[0] = ImageColorAllocate($base_image,255,255,255);$col[1] = ImageColorAllocate($base_image,0,0,0);//imagecolorallocate — 為一幅圖像分配顏色//第一個參數(shù)是建立的,后面三個分別是R,G,B(大小都是從0到255),你可以理解為顏料……,三個顏料不同比例混合產(chǎn)生了不同的顏色,所以$col[0]就是白色的畫筆啦,$col[1]是黑色的畫筆(為什么三個255是白色,三個0是黑色,你可以想象一下中學(xué)物理里面白光可以分解的實驗……)imagefill($base_image, 0, 0, $col[0]);//imagefill — 區(qū)域填充 ,整個畫布上面都是白色的啊for($y=0; $y<$h; $y++) {for($x=0; $x<$w; $x++) {if ($frame[$y][$x] == '1') {ImageSetPixel ($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); }}}//通過兩個循環(huán),將$tab數(shù)組中的1填充為黑色,剩下的0為白//$outerFrame表示留白$target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);//ImageCreate這個函數(shù)剛剛介紹過了,干嘛又調(diào)用…………而且大小是原來的$pixelPerPoint倍!//好吧,$pixelPerPoint是放大倍數(shù),這里開始將剛剛生成的畫按需放大(現(xiàn)在只是生成放大的畫布)ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);//imagecopyresized — 拷貝部分圖像并調(diào)整大小 //將剛剛的畫放大$pixelPerPoint倍之后復(fù)制到新建的畫布里面ImageDestroy($base_image);//imagedestroy — 銷毀一圖像 return $target_image;//返回生成的最后圖像!}

4、自己的才是踏實的。

So…………

(1)可以將“黑點”變成彩色的點?變成愛心?,變成你女朋友的照片?變成文字?

(2)可以再圖像中間部分加點東西,一個“愛”字,還是什么能夠表達力心意的東西?

5、編寫自己的方法

private static function myImage($frame, $pixelPerPoint = 4, $outerFrame = 4, $point, $centerPoint ){/* * array $point 表示所填充的點的樣式 * array $centerPoint 表示圖片中間部分的樣式 * $point = array('kind'=>'',//col,img,Word'info'=>'' //rgb,filename) * $centerPoint = array('kind'=>'',//col,img,word'info'=>'') * 沒有編寫完,但是思路是一樣的 */if($point['kind'] == 'col'){$R1 = $point['info']['0']['R'];$G1 = $point['info']['0']['G'];$B1 = $point['info']['0']['B'];$R2 = $point['info']['1']['R'];$G2 = $point['info']['1']['G'];$B2 = $point['info']['1']['B'];$h = count($frame);$w = strlen($frame[0]);$imgW = $w + 2*$outerFrame;$imgH = $h + 2*$outerFrame;$base_image =ImageCreate($imgW, $imgH);$col[0] = ImageColorAllocate($base_image,$R1,$G1,$B1);$col[1] = ImageColorAllocate($base_image,$R2,$G2,$B2);imagefill($base_image, 0, 0, $col[0]);for($y=0; $y<$h; $y++) {for($x=0; $x<$w; $x++) {if ($frame[$y][$x] == '1') {ImageSetPixel ($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); }}}//////////////////////x$target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);ImageDestroy($base_image);return $target_image;}elseif($point['kind'] == 'img'){function getSquare($image, $multi){$imgW = imagesx($image);$imgH = imagesy($image);$imgMin = min($imgH,$imgW);$target_image =imagecreatetruecolor($imgMin,$imgMin);imagecopyresampled($target_image, $image, 0, 0, 0, 0, $imgMin , $imgMin, $imgW, $imgH);//ImageCopyResized($target_image, $image, 0, 0, 0, 0, $imgW * $multi, $imgH * $multi, $imgW, $imgH);$multi_image =imagecreatetruecolor($imgMin*$multi,$imgMin*$multi);imagecopyresampled($multi_image, $target_image, 0, 0, 0, 0, $imgMin*$multi,$imgMin*$multi, $imgMin, $imgMin);//ImageCopyResized($target_image, $image, 0, 0, 0, 0, $imgW * $multi, $imgH * $multi, $imgW, $imgH);ImageDestroy($image);return $multi_image;}function getSameSize($image,$pixelPerPoint){$imgW = imagesx($image);$imgH = imagesy($image);$target_image =imagecreatetruecolor($pixelPerPoint,$pixelPerPoint);ImageCopyResized($target_image, $image, 0, 0, 0, 0, $pixelPerPoint , $pixelPerPoint, $imgW, $imgH);//ImageCopyResized($target_image, $
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 和林格尔县| 大关县| 罗田县| 嵩明县| 马关县| 尚义县| 京山县| 宁安市| 汨罗市| 台州市| 邻水| 且末县| 开远市| 尼木县| 玉树县| 长寿区| 正安县| 平远县| 崇州市| 河津市| 乌兰县| 贞丰县| 奈曼旗| 雷山县| 乐亭县| 平南县| 葵青区| 巩留县| 河北省| 新余市| 兴宁市| 麻江县| 苍山县| 红河县| 南乐县| 朝阳市| 罗定市| 巴南区| 乌审旗| 汉沽区| 于田县|