PHP implementation of simple synthetic image method

Source: Internet
Author: User

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 ', ');        }    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.