個人化自己的二維碼,個人化自己二維碼
一、什麼是二維碼
二、我們如何製作二維碼
三、如何製作自己的個性二維碼
1、第一步。下載Php類庫phpqrcode,(附下載地址:http://sourceforge.net/projects/phpqrcode/)
網上給出的使用案列是:
2、看懂上面的代碼
上面那段代碼發生了什麼奇妙的旅程呢?
讓我麼開啟phpqrcode.php看一看,代碼太長了,就不貼了,各位自己下載去吧。
結合上面的代碼和phpqrcode.php,看一看:
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);/*標記*/$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;?>
我們可以發現,php類庫phpqrcode首先通過一種演算法將我們需要的文字轉化為數組$tab ,然後通過映像操作畫了一張圖片,也就是我們的二維碼。
如果列印數組$tab,就會發現他就是這樣的:
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)
好吧,你懂了嗎…………
現在就簡單了,根據數組$tab,畫畫就可以了:
QRimage::png($tab, $outfile, min(max(1, $enc->size), $maxSize), $enc->margin,$saveandprint);
3、如何畫畫
如果我們人人研究源碼,會發現最關鍵的是這樣一個方法:
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4);
下面貼出我注釋過的源碼(原類庫是沒有注釋的)
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, $image, 0, 0, 0, 0, $imgW * $multi, $imgH * $multi, $imgW, $imgH);ImageDestroy($image);return $target_image;}$h = count($frame);$w = strlen($frame[0]);$imgW = $w + 2*$outerFrame;$imgH = $h + 2*$outerFrame;$base_image =ImageCreate($imgW*$pixelPerPoint, $imgH*$pixelPerPoint);imagefill($base_image, 0, 0, ImageColorAllocate($base_image,255,255,255));$pointimg = imagecreatefromjpeg ($point['info']);$newimg = getSquare($pointimg, 1);$newimgpoint = getSameSize($newimg,$pixelPerPoint);for($y=0; $y<$h; $y++) {for($x=0; $x<$w; $x++) {if ($frame[$y][$x] == '1') {imagecopyresampled($base_image, $newimgpoint, $y*$pixelPerPoint, $x*$pixelPerPoint, 0, 0, $pixelPerPoint, $pixelPerPoint, $pixelPerPoint, $pixelPerPoint);}}}return $base_image;}elseif($point['kind'] == 'word'){}else{$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,255,255,255);$col[1] = ImageColorAllocate($base_image,0,0,0);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;} }
個性二維碼怎做?
目前,不論企業還是個人網站,甚至連媒介平台都貼出了自己的二維碼,一來可以迎合市場需求,二來可以擷取眾人眼球。正因二維碼需求的不斷擴張,市面上二維碼產生器種類也越來越多。但是,多數二維碼產生器產生的二維碼為黑白色,外形都比較單一,沒什麼特色。若想追求個性,產生彩色二維碼,可以看看芝麻網是怎麼做到的。
我們在日常生活中見到最多的二維碼產生器產生的二維碼無非是右上、左上、左下各有一個規則正方形的矩陣式二維碼,具有資訊擷取(文本、名片、地圖、WIFI密碼、網址、簡訊、視頻)等功能,芝麻二維碼產生器則不只局限於此。芝麻二維碼產生器不僅可以通過輸入文本、名片、網址、WIFI、地圖、圖片、MP3、芝麻號等資訊產生二維碼,而且可以依照使用者喜好改變形狀顏色甚至個性模板產生具有個性圖案和色彩的二維碼。
芝麻網產生二維碼介面
如何在芝麻網產生彩色二維碼
1、註冊成為芝麻使用者
2、選擇文本、名片、網址、WIFI、地圖、圖片、MP3、芝麻號中的任一類型
3、填寫待產生的內容產生二維碼,可以選擇普通二維碼以及個人化模版。如若選擇普通二維碼可根據個人喜好選擇喜歡的顏色,添加LOGO或是調整形狀產生二維碼;如若選擇個人化模版則可選擇喜歡的模版產生個性好玩的二維碼,右側可即時顯示產生的二維碼預覽,最後可將產生的二維碼下載到本地!
普通二維碼
個人化模版
產生彩色二維碼很簡單,趕緊試試吧!鈉)
怎產生個性好玩的二維碼?
現在網上產生器軟體眾多,但大多沒什麼新意,最近嘗試了一下用芝麻網新出爐的二維碼產生器,果然木有令我失望啊,該產生器可以隨意的調整顏色和漸層方式,還能調整形狀,加入logo,尤其是還可以選擇個人化模版讓二維碼變得可愛靈動起來。
http://www.bkjia.com/PHPjc/860061.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/860061.htmlTechArticle個人化自己的二維碼,個人化自己二維碼 一、什麼是二維碼 二、我們如何製作二維碼 三、如何製作自己的個性二維碼 1、第一步。下載P...