>  기사  >  php教程  >  사진으로 QR 코드 생성

사진으로 QR 코드 생성

WBOY
WBOY원래의
2016-09-07 12:57:581585검색

이제 막 시작했는데, 고수님들이 이해하기 쉽지 않을 수도 있겠네요.

단계: 1. 웹사이트 http://phpqrcode.sourceforge.net/에서 phpqrcode.php 파일을 다운로드한 다음 자신의 프로젝트에 넣습니다.

2. 코드를 작성하고 phpqrcode.php 파일을 도입하여 QR 코드를 생성합니다.

코드:

1. phpqrcode.php 파일(그냥 다운로드하세요)

2. 테스트 코드(erweima.app.php)

/*
 * 生成二维码
 */
class ErweimaApp은 ShoppingbaseApp을 확장합니다.{
    
    함수 인덱스()
    {
$this->display('erweima.html');
    }

    /**
* @param string $chl QR 코드에 포함되는 정보는 숫자, 문자, 바이너리 정보, 한자일 수 있습니다.
데이터 유형을 혼합할 수 없으며 데이터는 UTF-8 URL로 인코딩되어야 합니다.
* @param int $widhtHeight QR 코드 생성을 위한 크기 설정
* @param string $EC_level 선택적 오류 수정 수준, QR 코드 4개 지원 손실, 잘못 읽음, 모호함 및 데이터를 복구하기 위한 오류 수정 수준입니다.
* L-기본값: 손실된 데이터의 7%를 식별할 수 있습니다
* M-손실된 데이터의 15%를 식별할 수 있습니다
* Q-손실된 데이터의 25%를 식별할 수 있습니다
* H -30% 손실된 데이터 식별 가능
* @param int $margin 생성된 QR 코드와 이미지 테두리 사이의 거리
*/
    function Credit_qrcode()
    {
        include '/includes /라이브러리/phpqrcode.php';
        $value = isset($_POST['url']) ? $_POST['url'] : 'http://www.baidu.com';
        //상위 사진
        if (isset($_FILES['image']) && $_FILES['image'] ['error'] == 0 ){
            $image = $this->_upload_file('image', 'erweima/', date('YmdHis') . mt_rand(1000, 9999), 'index.php ?app=credit&act=credit_qrcode');
            if ($image){
               $logo = $image;
           }
        }
        else
        {
            $logo = SITE_URL. '/themes/mall/default/styles/default/images/001.jpg';//准备好的로고그림
        }
        $errorCorrectionLevel = 'H';//容错级别
    $matrixPointSize = 8;//生成图文大小
    //生成日维码图文
    QRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2);
    $QR = 'qrcode.png';//已经生成長始二维码图
        
        if($logo !== FALSE){
            $QR = imagecreatefromstring(file_get_contents($ QR )));
            $logo = imagecreatefromstring(file_get_contents($logo));             $logo_height = imagey($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($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,
           $logo_qr_height, 로고_너비, $로고_높이);  
        }
        //출처 사진
    imagepng($QR, 'helloweba.png');
    echo '';
    }
    
/**
* 파일 업로드
* @return mix false는 업로드 실패, 빈 문자열은 업로드 없음, 문자열은 업로드 파일 주소를 의미
* $file_name은 업로드 파일 이름
* $path_name은 업로드 경로
* $save_name은 저장 파일 이름
* $ret_url은 콜백 URL
**/
함수 _upload_file($file_name, $path_name, $save_name, $ret_url = 'index.php')
{
$file = $_FILES[$file_name];
                                                                                                                                                                                         HTML 형식의 MAX_FILE_SIZE 옵션에 의해 지정된 값입니다. 파일의 일부만 업로드되었습니다. '
스위치($file['error'] )
{
사례 UPLOAD_ERR_INI_SIZE:
사례 UPLOAD_ERR_FORM_SIZE:
사례 UPLOAD_ERR_PARTIAL:
if ($ret_url)
                                                                                                         ];
                                            SE, 'msg' => $message[$file ['error']]);
                                                                    ''를 반환합니다.
}
                  import('uploader.lib');                                                                 파일 );
if ($uploader- >file_info() === false)
{
if ($ret_url)
$this->show_war ning($uploader-> ;get_error(), 'go_back', $ret_url); > get_error()); '.$path_name, $save_name);
}
}



3. 템플릿 파일(erweima.html)

 


       

               请输入网址:

图文上传:

              

 

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:아약스의 해부학다음 기사:아약스의 해부학