config = Dever::config('base', 'project')->qrcode; $this->config = Dever::config('base', 'qrcode')->qrcode; Dever::apply('lib/phpqrcode'); } public function qrcode($string, $local = false, $logo = false, $uid = false) { if ($local) { $this->config['local'] = true; } if ($this->config['local']) { $result = $this->create($string, $local, $logo, $uid); } else { $result = $this->create($string); } return $result; } private function create($value, $local = false, $logo = false, $uid = false) { $file = false; if ($local) { if ($uid) { $path = Dever::pathAvatar($this->path, $uid); } else { $path = Dever::pathDay($this->path); } $file = $path . $local . '.png'; } if (!is_file($file)) { $QR = \QRcode::png($value, $file, 'L', $this->config['size'], 2); if ($logo) { if (strstr($file, 'http')) { $file_string = Dever::curl($file); } else { $file_string = file_get_contents($file); } if (Dever::project('upload')) { $logo_string = Dever::load('upload/lib/file')->content($logo); } else { $logo_string = file_get_contents($logo); } $QR = imagecreatefromstring($file_string); $logo = imagecreatefromstring($logo_string); $QR_width = imagesx($QR);//二维码图片宽度 $QR_height = imagesy($QR);//二维码图片高度 $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($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height);//输出图片 imagepng($QR, $file); } } $url = str_replace(Dever::data() . 'upload/', Dever::config('host')->uploadRes, $file); $result = array ( 'local' => $file, 'url' => $url, ); return $result; } }