1. 程式人生 > >PHP生成圓角二維碼logo

PHP生成圓角二維碼logo

分享圖片 function center info 分享 amp ges images inf

PHP生成圓角二維碼logo

技術分享圖片

function cornerimg($filename, $cornerimg, $logoimg, $centerbigger=5){
    //獲取二維碼
    $qrcode = file_get_contents($filename);
    $qrcode = imagecreatefromstring($qrcode);
    $qrcode_width = imagesx($qrcode);
    $qrcode_height = imagesy($qrcode);

//圓角圖片
    $corner = file_get_contents
($cornerimg); $corner = imagecreatefromstring($corner); $corner_width = imagesx($corner); $corner_height = imagesy($corner); //計算圓角圖片的寬高及相對於二維碼的擺放位置,將圓角圖片拷貝到二維碼中央 $corner_qr_height = $corner_qr_width = $qrcode_width/$centerbigger; $from_width = ($qrcode_width-$corner_qr_width
)/2; imagecopyresampled($qrcode, $corner, $from_width, $from_width, 0, 0, $corner_qr_width, $corner_qr_height, $corner_width, $corner_height); //logo圖片 $logo = file_get_contents($logoimg); $logo = imagecreatefromstring($logo); $logo_width = imagesx($logo); $logo_height = imagesy($logo
); //計算logo圖片的寬高及相對於二維碼的擺放位置,將logo拷貝到二維碼中央 $logo_qr_height = $logo_qr_width = $qrcode_width/$centerbigger - 6; $from_width = ($qrcode_width-$logo_qr_width)/2; imagecopyresampled($qrcode, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height); header(‘Content-type: image/png‘); imagepng($qrcode); imagedestroy($qrcode); imagedestroy($corner); imagedestroy($logo); }

PHP生成圓角二維碼logo