php產生二維碼

來源:互聯網
上載者:User

標籤:bsp   二維碼   ror   oms   obj   str   led   new   int   

//https://sourceforge.net/projects/phpqrcode/files/   include ‘phpqrcode/phpqrcode.php‘;class MyQrcode{    /*     * 普通產生二維碼     * @param string $url     * @param int $size     * @param string $output_path     * @param string $filename     * @return array     */    public function createNormal($url=‘‘,$size=4,$output_path=‘‘,$filename=‘‘)    {        if(empty($url))        {            return array(‘result‘=>"fail",‘msg‘=>"url參數為空白");        }        if(empty($path))        {            $output_path=‘./‘;        }        if(empty($filename))        {            $filename=md5(time()).‘.png‘;        }        //容錯層級        $errorCorrenctionLevel = ‘l‘;        Qrcode::png($url,$output_path.$filename,$errorCorrenctionLevel,$size,2);        return array(‘result‘=>‘success‘,‘msg‘=>"產生成功",‘imgurl‘=>$output_path.$filename);    }    public function createHasCenterImage($url=‘‘,$centerImg=‘‘,$size=4,$output_path=‘‘,$output_filename=‘‘,$tempfile=‘temp.png‘)    {        if(empty($url))        {            return array(‘result‘=>"fail",‘msg‘=>"url參數為空白");        }        if(empty($path))        {            $output_path=‘./‘;        }        if(empty($output_filename))        {            $output_filename=md5(time()).‘.png‘;        }        if(empty($centerImg))        {            return array(‘result‘=>"fail",‘msg‘=>"中心圖片參數為空白");        }        if(!file_exists($centerImg))        {            return array(‘result‘=>"fail",‘msg‘=>"中心圖片不存在");        }        //容錯層級        $errorCorrenctionLevel = ‘l‘;        Qrcode::png($url,$tempfile,$errorCorrenctionLevel,$size,2);        if(!file_exists($tempfile))        {            return array(‘result‘=>"fail",‘msg‘=>"產生臨時二維碼失敗");        }        $logo = $centerImg;        $qrcode = $tempfile;        $logo = imagecreatefromstring(file_get_contents($logo));        $qrcode = imagecreatefromstring(file_get_contents($qrcode));        $QR_width = imagesx($qrcode);//二維碼圖片寬度        $QR_height = imagesy($qrcode);//二維碼圖片高度        $logo_width = imagesx($logo);//logo圖片寬度        $logo_height = imagesy($logo);//logo圖片高度        $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;        //重新組合圖片並調整大小        imagecopyresampled($qrcode, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height);        //儲存產生的二維碼        $r= imagepng($qrcode,$output_path.$output_filename);        //刪除臨時的二維碼圖片        @unlink($tempfile);        if($r==true)        {            return array(‘result‘=>"success",‘msg‘=>"產生二維碼成功",‘imgurl‘=>$output_path.$output_filename);        }        else        {            return array(‘result‘=>"fail",‘msg‘=>"產生二維碼失敗");        }    }}$obj=new MyQrcode();$obj->createNormal(‘http://www.baidu.com‘,4,‘./‘.‘tt.png‘);

 

php產生二維碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.