1 download generate two-dimensional code library
composer require aferrandini/phpqrcode
2 Click the button to download
//二维码下载 public function down_qrcode() { if($this->request->isPost()){ $shop_id = input('shop_id'); $merchant_id = Db::table('xcf_shops')->where('shop_id',$shop_id)->value('merchant_id'); if($merchant_id){ $url = 'xcf'.$merchant_id; //二维码内容 $pic = $this->scerweima1($url); return $pic; } The else { return JSON ([ 'S' => 'error', 'MSG' => 'merchant_id does not exist, please review rich friends' ]); } } }
// generates a two-dimensional code // 2 plus logo (an image file generation) generated in a two-dimensional code. Public function scerweima1 ( $ text ) { // echo 'Hee'; Die; // the dump (APP_XCF_LOG.'xcf .png '); Die; //Vendor('chillerlan.php-qrcode.public.qrcode'); // pathname = DATE $ ( "Ymd", Time ()); $ pathname = APP_PATH '/../. public / Upload / qrcode / ' ; IF (! is_dir ( $ pathname {)) // if the directory does not exist it is created mkdir ( $ pathname , 0777, to true ); } $ errorCorrectionLevel= 'H'; // fault tolerance level $ matrixPointSize = 10; // generates a picture size // dimensional code image generated $ ABC = DATE ( "Ymd", Time ()). Time () 'PNG.'. ; $ filename = $ pathname . $ ABC ; \ PHPQRCode \ QRcode :: PNG ( $ text , $ filename , $ errorCorrectionLevel , $ matrixPointSize , 2 ); $ logo = APP_PATH '/../public/assets/xcf_log/xcf.png. '; // ready logo image The dump // (APP_XCF_LOG.'xcf.png '); Die; // the dump ($ logo); Die; $ the QR = $ filename ; // already generated original two-dimensional code pattern // the dump ($ the QR); IF ( the file_exists ( $ logo )) { $ the QR = imagecreatefromstring ( file_get_contents ( $ the QR )); // target image connection resources. logo $ = imagecreatefromstring ( file_get_contents ( $ logo )); // source image connection resources. QR_width $ = imagesx ( $ QR ); // two-dimensional code image width $ QR_heightImagesy = ( $ the 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 /. 4; // logo after the combined width (1/5 of the two-dimensional code) $ scale = $ logo_width / $ logo_qr_width ; // logo width scaling ratio (width after itself width / composition) $ logo_qr_height = $ logo_height / $ scale ; // logo after the combined height $ from_width = ( $ QR_width- $ logo_qr_width ) / 2; // left corner coordinates of the point where the logo after combining // recombined image and resize / * * imagecopyresampled () a rectangular portion of an image (image source) is copied to another image in * / imagecopyresampled ( $ the QR , $ logo , $ from_width , $ from_width , 0, 0, $ logo_qr_width , $ logo_qr_height , $ logo_width , $ logo_height ); } // output image imagepng ( $ the QR , $ filename ); return Request () -> domain () ' / upload / qrcode /'..$abc; }