|
@@ -5,6 +5,7 @@ use Dever;
|
|
|
|
|
|
class Api
|
|
|
{
|
|
|
+ private $path = 'upload/qrcode';
|
|
|
public function __construct()
|
|
|
{
|
|
|
|
|
@@ -12,23 +13,52 @@ class Api
|
|
|
Dever::apply('lib/phpqrcode');
|
|
|
}
|
|
|
|
|
|
- public function qrcode($string)
|
|
|
+ public function qrcode($string, $local = false, $logo = false)
|
|
|
{
|
|
|
+ if ($local) {
|
|
|
+ $this->config['local'] = true;
|
|
|
+ }
|
|
|
if ($this->config['local']) {
|
|
|
- $result = $this->createFile($string);
|
|
|
+ $result = $this->create($string, $local, $logo);
|
|
|
} else {
|
|
|
$result = $this->create($string);
|
|
|
}
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
- private function create($value)
|
|
|
+ private function create($value, $local = false, $logo = false)
|
|
|
{
|
|
|
- $QR = \QRcode::png($value, false, 'L', $this->config['size'], 2);
|
|
|
- }
|
|
|
+ $file = false;
|
|
|
+ if ($local) {
|
|
|
+ $path = Dever::pathDay($this->path);
|
|
|
+ $file = $path . $local . '.png';
|
|
|
+ }
|
|
|
+ if (!is_file($file)) {
|
|
|
+ $QR = \QRcode::png($value, $file, 'L', $this->config['size'], 2);
|
|
|
|
|
|
- private function createFile($string)
|
|
|
- {
|
|
|
- echo 22;die;
|
|
|
+ if ($logo) {
|
|
|
+ $logo = Dever::local($logo);
|
|
|
+ $QR = imagecreatefromstring(file_get_contents($file));
|
|
|
+ $logo = imagecreatefromstring(file_get_contents($logo));
|
|
|
+ $QR_width = imagesx($QR);
|
|
|
+ $QR_height = imagesy($QR);
|
|
|
+ $logo_width = imagesx($logo);
|
|
|
+ $logo_height = imagesy($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;
|
|
|
}
|
|
|
}
|