PHP generates two-dimensional code

Source: Internet
Author: User

//https://sourceforge.net/projects/phpqrcode/files/include' Phpqrcode/phpqrcode.php ';classmyqrcode{/** Ordinary generation of QR code * @param string $url * @param int $size * @param string $output _path * @param string $f Ilename * @return Array*/     Public functionCreatenormal ($url= ",$size=4,$output _path= ",$filename= ' ')    {        if(Empty($url))        {            return Array(' result ' = ' fail ', ' msg ' = ' = ' url parameter is null '); }        if(Empty($path))        {            $output _path= './'; }        if(Empty($filename))        {            $filename=MD5( Time()).‘. png; }        //Fault tolerance level        $errorCorrenctionLevel= ' L '; QRCode::p ng ($url,$output _path.$filename,$errorCorrenctionLevel,$size, 2); return Array(' result ' = ' success ', ' msg ' = ' generate success ', ' imgurl ' =$output _path.$filename); }     Public functionCreatehascenterimage ($url= ",$centerImg= ",$size=4,$output _path= ",$output _filename= ",$tempfile= ' Temp.png ')    {        if(Empty($url))        {            return Array(' result ' = ' fail ', ' msg ' = ' = ' url parameter is null '); }        if(Empty($path))        {            $output _path= './'; }        if(Empty($output _filename))        {            $output _filename=MD5( Time()).‘. png; }        if(Empty($centerImg))        {            return Array(' result ' = ' fail ', ' msg ' = ' = ' center picture parameter is null '); }        if(!file_exists($centerImg))        {            return Array(' result ' = ' fail ', ' msg ' = ' "center picture does not exist"); }        //Fault tolerance level        $errorCorrenctionLevel= ' L '; QRCode::p ng ($url,$tempfile,$errorCorrenctionLevel,$size, 2); if(!file_exists($tempfile))        {            return Array(' result ' = ' fail ', ' msg ' = ' = ' Generate temporary QR code failed '); }        $logo=$centerImg; $qrcode=$tempfile; $logo= Imagecreatefromstring (file_get_contents($logo)); $qrcode= Imagecreatefromstring (file_get_contents($qrcode)); $QR _width= Imagesx ($qrcode);//Two-dimensional code image width        $QR _height= Imagesy ($qrcode);//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 ($qrcode,$logo,$from _width,$from _width, 0, 0,$logo _qr_width,$logo _qr_height,$logo _width,$logo _height); //Save the generated QR code        $r= Imagepng ($qrcode,$output _path.$output _filename); //Delete a temporary QR code image@unlink($tempfile); if($r==true)        {            return Array(' result ' = ' success ', ' msg ' = ' Generate QR code success ', ' imgurl ' =$output _path.$output _filename); }        Else        {            return Array(' result ' = ' fail ', ' msg ' = ' Generate QR code failed '); }    }}$obj=NewMyqrcode ();$obj->createnormal (' http://www.baidu.com ', 4, './'. ') Tt.png ');

PHP generates two-dimensional code

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.