-
-
class QRCode{
- public $w;
- 公$h;
- 公$;
- 函數 __construct($w1,$h1,$s1){
- $this->w = $w1;
- $this->h = $h1;
- $this->s = $s1;
- $this->outimgase();
- }
- 函數 qrcode(){
- $post_data = array();
- $post_data['cht'] = 'qr';
- $post_data['chs'] = $this->w."x".$this->h;
- $post_data['chl'] = $this->s;
- $post_data['choe'] = "UTF-8";
- $url = "http://chart.apis.google.com/chart";
- $data_Array = array();
- foreach($post_data as $key => $value)
- {
- $data_Array[] = $key.'='.$value;
- }
- $data = implode("&",$data_Array);
- $ch=curl_init();
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $結果=curl_exec($ch);
- curl_close($ch);
- 回傳$結果;
- }
- function outimgase(){
- echo $this->qrcode();
- }
- }
- header("內容型態:image/png");
- $t = new QRCode(300,300,"tianxin");
複製程式碼
2,然後,透過一個php檔案將二維碼和你的目的圖片畫在一起。
-
-
$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($filename, "a");
- fwrite($fp2,$img);
- fclose($fp2);
- 回傳$檔名;
- }
- $source = GrabImage("http://localhost/QRCode/QRCode.php","Myqrcode.png");
- $water =GrabImage($surl,"t.png");
- 函數 getImageInfo($img){
- $imageInfo = getimagesize($img);
- if ($imageInfo !== false) {
- $imageType = strtolower(substr(image_type_to_extension($imageInfo[2]), 1));
- $imageSize = 檔案大小($img);
- $info = array(
- "寬度" => $imageInfo[0],
- "高度" => $imageInfo[1],
- "類型" => $imageType,
- "大小" => $imageSize,
- "mime" => $imageInfo['mime']
- );
- 回傳$訊息;
- } else {
- 回傳 false;
- }
- }
- functionthumb($image, $thumbname, $type='', $maxWidth=200, $maxHeight=50, $interlace=true) {
- //取得原圖資訊
- $info = getImageInfo($image);
- if ($info !== false) {
- $srcWidth = $info['width'];
- $srcHeight = $info['height'];
- $type = 空($type) ? $info['type'] : $type;
- $type = strtolower($type);
- $交錯 = $交錯?
- $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);
- 其他
- $thumbImg = imagecreate($width, $height);
- // 複製圖片
- if (function_exists("ImageCopyResampled"))
- imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $widumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcImg. ;
- else
- imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
- if ('gif' == $type || 'png' == $type) {
- //imagealphablending($thumbImg, false);//取消預設的混色模式
- //imagesavealpha( $thumbImg,true);//設定保存完整的alpha通道資訊
- $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;
- }
- 功能水($source, $thumb, $savename="", $alpha=100){
- //檢查檔案是否存在
- if (!file_exists($source) || !file_exists($thumb))
- 回傳false;
- //圖片資訊
- $sInfo = getImageInfo($source);
- $水 = 拇指($thumb,"wy.jpg","jpg",$sInfo["寬度"]/4,$sInfo["高度"]/4);
- $wInfo = getImageInfo($water);
- //如果圖片小於浮水印圖片,不產生圖片
- if ($sInfo["width"] 返回false;
- //建立映像
- $sCreateFun = "imagecreatefrom" . $sInfo['類型'];
- $sImage = $sCreateFun($source);
- $wCreateFun = "imagecreatefrom" 。
- $wImage = $wCreateFun($water);
- //設定影像的混色模式
- imagealphablending($wImage, true);
- //影像位置,預設為右下角右對齊
- // $posY = $sInfo["height"] - $wInfo["height"];
- // $posX = $sInfo["width"] - $wInfo["width"];
- $posY = ($sInfo["height"] - $wInfo["height"])/2;
- $posX = ($sInfo["width"] - $wInfo["width"])/2;
- //產生混合影像
- imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo['width'], $wInfo['height'], $alpha);
- //輸出影像
- $ImageFun = 'Image' . $sInfo['類型'];
- //如果沒有給予儲存檔名,預設為原始影像名稱
- if (!$savename) {
- $savename = $source;
- @unlink($source);
- }
- //儲存影像
- $ImageFun($sImage, $savename);
- imagedestroy($sImage);
- }
- water($source,$water);
-
複製程式碼
在上面的程式碼中用3個函數GrabImage()函數是將產生二維碼的檔案轉換成圖片接下來的函數就是處理圖片的縮放將目的圖片添加到二位。
3,在來一個入口文件index.html 程式碼如下:
-
-
-
-
中間可以自己定義圖片的二維碼產生器_bbs.it-home .org
-
-
複製程式碼
|