This article is mainly to share with you PHP implementation of simple synthetic image method, mainly in the form of code and we share, hope to help everyone.
1. Encapsulation function
Generate two-dimensional code function Qr_user_code ($url _code, $uid) {header ("access-control-allow-origin:*"); Vendor (' Phpqrcode.phpqrcode ');//reference Phpqrcode class Package $url = $url _code; $errorCorrectionLevel = ' H ';//tolerance level $matrixPointSize = 5;//picture size Slowly adjust itself, as long as the int on the line $path = ' user_cache/'; if (!file_exists ($path)) {mkdir ($path); } $QR = $QRB = $path. Rand (10000,99999). Time (). ". PNG "; \qrcode::p ng ($url, $QR, $errorCorrectionLevel, $matrixPointSize, 2); $dst _path = ' 20180326171846.png ';//web\lalpbbcc1vataevna4dnanw_636_896.png $src _path = $QR;//overlay map//Create an instance of a picture $dst = Imagecreatefromstring (file_get_contents ($DST _path)); $SRC = imagecreatefromstring (file_get_contents ($src _path));//Get the overlay image of the wide list ($src _w, $src _h) = getimagesize ($src _ path),///To copy the overlay to the target image, the last parameter 100 is to set the transparency (100 is opaque), here to achieve the opacity effect Imagecopymerge ($DST, $SRC, 184, 410, 0, 0, 286, 286, 100);// @unlink ($QIMG); Delete the two-dimensional code and logo of the composite Image @unlink ($QRB); Delete the QR code image header ("Content-type:image/png") on the server; Imagepng ($DST, ' Uploads/user/'. $uid. PNG ');//Imagejpeg ($DST, '. /uploads/user/'. $uid. JPG '); Imagedestroy ($DST); Imagedestroy ($SRC);}
2. Call the function of step one
Public Function Qr_code ($uid) { $url = ' http://ypyz.yxyzyl.com/template/mobile/xian/static/takehtml/ Personalhtml/bind.html?uid= '. $uid; Qr_user_code ($url, $uid);//Because I enclose it in common, so call $time = time (); $path = '/uploads/user/'. $uid. PNG '; $sha 1 = SHA1 ($uid. $time. PNG '); $res = (new Us ())->where ([' user_id ' = ' = $uid])->update ([' qr_code ' = ' + $sha 1]); $re = db (' picture ')->insert ([ ' path ' = = $path, ' sha1 ' = + $sha 1, ' status ' =>1, ' Create_ Time ' = $time ]); if ($res!== false&& $re!=false) { $this->assign (' path ', $path); return $this->fetch (); } else { $this->error (' Generate QR code failed ', '); } }