Пример #1
0
 protected function getLocal()
 {
     $outputDir = $this->getOutputDir();
     $filename = $this->getFilename();
     $saveFilename = $outputDir . '/' . $filename;
     $webFilename = $this->getOutputDirWeb() . '/' . $filename;
     if (false === file_exists($saveFilename)) {
         QRcode::init($this->qrOptions);
         //save file
         QRcode::png($this->text, $saveFilename, $this->ecLevel, $this->size, $this->margin);
     }
     //render img tag
     return Html::img($webFilename, $this->imgOptions);
 }
Пример #2
0
 public function run($text)
 {
     $size = $this->defaultSize;
     $margin = $this->defaultMargin;
     $ecLevel = $this->ecLevel;
     $this->text = $text;
     if (empty($text)) {
         throw new HttpException(404, 'QR is not exist.');
     }
     if (true === $this->allowClientSize) {
         $clientSize = intval(Yii::$app->request->get('size', $this->defaultSize));
         if ($clientSize >= $this->defaultSize && $clientSize <= $this->maxSize) {
             $this->defaultSize = $clientSize;
         }
     }
     if (true === $this->allowClientMargin) {
         $clientMargin = intval(Yii::$app->request->get('margin', $this->defaultMargin));
         if ($clientMargin >= $this->defaultMargin && $clientMargin <= $this->maxMargin) {
             $this->defaultMargin = $clientMargin;
         }
     }
     if (true === $this->allowClientEclevel) {
         $clientEclevel = intval(Yii::$app->request->get('ec', $this->ecLevel));
         $ecOptions = QRcode::getEclevelOptions();
         if (in_array($clientEclevel, $ecOptions)) {
             $this->ecLevel = $clientEclevel;
         }
     }
     if ($this->outputDir === null) {
         $outputfile = null;
     } elseif (is_callable($this->onGetFilename)) {
         $outputfile = $this->getOutputDir() . DIRECTORY_SEPARATOR . call_user_func_array($this->onGetFilename, [$this]);
     } else {
         $outputfile = $this->getOutputDir() . DIRECTORY_SEPARATOR . $this->getFilename();
     }
     QRcode::init(ArrayHelper::merge($this->options, ['QR_CACHEABLE' => $this->enableCache]));
     header('Content-Type: image/png');
     QRcode::png($text, $outputfile, $this->ecLevel, $this->defaultSize, $this->defaultMargin, true);
 }