PHP_PHP チュートリアルを使用して、中央に独自の定義を含む画像の QR コードを作成する方法

WBOY
リリース: 2016-07-13 10:39:45
オリジナル
829 人が閲覧しました

1. まず、QR コードを生成する必要があります。

コードをコピーします。 コードは次のとおりです。
class QRCode{
public $h; $s;
関数 __construct($ w1,$h1,$s1){
$this->w = $w1;
$this->s = $s1;
$this->outimgase( );
}
関数 qrcode(){
$post_data['cht'] = 'qr'] = $this; ->w."x" .$this->h;
$post_data['chl'] = $this->s;
$post_data['choe'] = "UTF-8"; = "http://chart.apis.google.com/chart";
$data_Array = array();
foreach($post_data as $key => $value)
{
$data_Array[] = $key. '='.$value;
$data = implode("&",$data_Array);
curl_setopt($ch, CURLOPT_POST, 1); 0);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
$result =curl_exec($ch);閉じる($ch);
return $result;
function outimgase(){
echo $this->qrcode();
header("Content-type:image/png"); = new QRCode(300,300,"tianxin ");


2、次に PHP ファイルを通じて QR コードとターゲット画像を一緒に描画します。 コードは次のとおりです:




コードをコピーします。

コードは次のとおりです:

$surl = $_POST["url"];
function GrabImage($url,$filename="") {
if($url==""):return false;endif;
if($filename=="") {
$ext=strrchr($url,".");
if($ext!=".gif" && $ext!=".jpg"):return false;endif;
$filename=date("dMYHis").$ext;
}
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
$fp2=@fopen($ファイル名, "a");
fwrite($fp2,$img);
fclose($fp2);
$filename を返します;
}
$source = GrabImage("http://localhost/QRCode/QRCode.php","Myqrcode.png");
$water =GrabImage($surl,"t.png");
関数 getImageInfo($img){
$imageInfo = getimagesize($img);
if ($imageInfo !== false) {
$imageType = strto lower(substr(image_type_to_extension($imageInfo[2]), 1));
$imageSize = ファイルサイズ($img);
$info = array(
"幅" => $imageInfo[0],
"高さ" => $imageInfo[1],
"タイプ" => $imageType,
"サイズ" => $ imageSize,
"mime" => $imageInfo['mime']
);
$info を返します;
} else {
false を返す;
}
}
function subject($image, $thumbname, $type='', $maxWidth=200, $maxHeight=50, $interlace=true) {
// 获取原图情報
$info = getImageInfo($画像);
if ($info !== false) {
$srcWidth = $info['width'];
$srcHeight = $info['高さ'];
$type = 空($type) ? $info['type'] : $type;
$type = strto lower($type);
$インターレース = $インターレース ? 1:0;
設定解除($info);
$scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight); // 计算缩放比
if ($scale >= 1) {
// 超过原图大小不再缩略
$width = $srcWidth;
$height = $srcHeight;
} else {
// 缩略图尺寸
$width = (int) ($srcWidth * $scale);
$height = (int) ($srcHeight * $scale);
}
// ダウンロード入原图
$createFun = 'ImageCreateFrom' 。 ($type == 'jpg' ? 'jpeg' : $type);
$srcImg = $createFun($image);
//创建缩略図
if ($type != 'gif' && function_exists('imagecreatetruecolor'))
$thumbImg = imagecreatetruecolor($width, $height);
else
$thumbImg = imagecreate($width, $height);
// 复制图片
if (function_exists("ImageCopyResampled"))
imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
else
imagecopyresize($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
if ('gif' == $type || 'png' == $type) {
//imagealphablending($thumbImg, false);//取消默认の混色モード
//imagesavealpha($thumbImg,true); //完全に保存されるアルファ パス情報を設定します
$background_color = imagecolorallocate($thumbImg, 0, 255, 0); // 指派一个绿色
imagecolortransparent($thumbImg, $background_color); // 設定は透明色、若注释掉この行に表示される色の画像
}
}
// jpeg 图形設定を隔行扫描
if ('jpg' == $type || 'jpeg' == $type)
imageinterlace ($thumbImg、$interlace);

// 画像を生成
$imageFun = 'image' . ($type == 'jpg' ? 'jpeg' : $type);
$imageFun($thumbImg, $thumbname);
imagedestroy($thumbImg);
imagedestroy($srcImg);
$thumbname を返します;
}
false を返します。
}
function Water($source, $thumb, $savename="", $alpha=100){
//检查文件の有無
if (!file_exists($source) || !file_exists($thumb))
false を返します。
//画像情報
$sInfo = getImageInfo($source);
$water =親指($thumb,"wy.jpg","jpg",$sInfo["幅"]/4,$sInfo["高さ"]/4);
$wInfo = getImageInfo($water);
//場合は写真が水印の写真より小さく、写真は生成されません
if ($sInfo["width"] < $wInfo["width"] || $sInfo['height'] < $wInfo['height'])
false を返します。
//建立画像
$sCreateFun = "imagecreatefrom" . $sInfo['タイプ'];
$sImage = $sCreateFun($source);
$wCreateFun = "imagecreatefrom" . $wInfo['タイプ'];
$wImage = $wCreateFun($water);
//画像の混色モードを設定します
imagealphablending($wImage, true);
//画像の位置、默认は右下角右对齐
// $posY = $sInfo["height"] - $wInfo["height"];
// $posX = $sInfo["width"] - $wInfo["width"];
$posY = ($sInfo["高さ"] - $wInfo["高さ"])/2;
$posX = ($sInfo["幅"] - $wInfo["幅"])/2;
//混合画像生成
imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo['width'], $wInfo['height'], $alpha);
//出画像
$ImageFun = '画像' . $sInfo['タイプ'];
//如果没有给出保存文件名,默认是原画像名
if (!$savename) {
$savename = $source;
@リンク解除($source);
}
//画像保存
$ImageFun($sImage, $savename);
imagedestroy($sImage);
}
水($source,$water);
🎜
上記のコードでは、3 つの関数が使用されています。GrabImage() 関数は、QR コードを生成するファイルを画像に変換し、画像のスケーリングを処理し、ターゲット画像を 2 番目の位置に追加します。

3. 次のコードを含むエントリ ファイルindex.html を作成します:
コードは次のとおりです:
中央の QR コード ジェネレーターで独自の画像を定義できます



< form action="送信された URL に注意してください< /span> " メソッド="post">

中央のデバイス

の画像に独自のQRコード生成を定義します



< tr>


QR コードに生成されるコンテンツ:

独自の写真アドレスを追加してください:
type="submit" name="Submit" value= "必要な QR コードを生成します">/label>
/div>





http://www.bkjia.com/PHPjc/728109.html

www.bkjia.com

tru​​e

http://www.bkjia.com/PHPjc/728109.html

技術記事

1. まず、QR コードを生成する必要があります。次のようにコードをコピーします。 { $this-w = $w1 $...



;
関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!