<?PHP/** * Address: http://phpqrcode.sourceforge.net/* @param string $url the link to be generated * @param string $logo middle picture Address * @param string $dir The absolute path of the saved picture*/ functionQRCode ($url= ' www.hao123.com/',$logo= './assets/img/gm.jpg ') {Loader:: Import (' Phpqrcode.phpqrcode '); $value=$url;//Two-dimensional code content link $errorCorrectionLevel= ' M ';//Fault tolerance level $matrixPointSize= 8;//Generate picture size $dir=root_path. ' Public '. DS. ' Uploads '. DS. ' QRCode '. DS;//the path of the output picture $QR _dir=$dir.‘ Qrcode.png ';//original QR code path//Generate two-dimensional code image\qrcode::p ng ($value,$QR _dir,$errorCorrectionLevel,$matrixPointSize, 2); $logo=$logo;//Ready logo Image $QR=$QR _dir;//original two-dimensional code diagram that has been generated if($logo!==FALSE) { $QR= Imagecreatefromstring (file_get_contents($QR)); $logo= Imagecreatefromstring (file_get_contents($logo)); $QR _width= Imagesx ($QR);//Two-dimensional code image width $QR _height= Imagesy ($QR);//Two-dimensional code image height $logo _width= Imagesx ($logo);//logo image Width $logo _height= Imagesy ($logo);//logo Image Height $logo _qr_width=$QR _width/5; $scale=$logo _width/$logo _qr_width; $logo _qr_height=$logo _height/$scale; $from _width= ($QR _width-$logo _qr_width)/2; //Regroup and resize picturesImagecopyresampled ($QR,$logo,$from _width,$from _width, 0, 0,$logo _qr_width,$logo _qr_height,$logo _width,$logo _height); } //Output Picture $he _dir=$dir.‘ Helloweba.png ';//Reorganize picture PathsImagepng ($QR,$he _dir); $url _display=$he _dir; $this->view->assign (' Url_display ',$url _display); return $this->view->fetch (); }
Using QRCode class to make two-dimensional code under thinkphp