private function populateData() { $this->bgColorRGB = QrTagShape::hex2dec($this->bgColor); $data = QRCode::text($this->text, false, $this->error_level); $data = array_map('str_split', $data); array_walk_recursive($data, 'intval'); $this->data = $data; if ($this->dot instanceof QrTagShape && !$this->dot instanceof QrTagEffect) { $this->dot->bgColorRGB = $this->bgColorRGB; $this->dotImg = $this->dot->generate(); if (!is_resource($this->dotImg)) { throw new Exception('Dot must generate a valid image resource.'); } } else { if ($this->dot instanceof QrTagEffect) { $this->dot->bgColorRGB = $this->bgColorRGB; $this->dot->generate(); } } if (!$this->frameDot instanceof QrTagShape) { $this->frameDot->bgColorRGB = $this->bgColorRGB; throw new Exception('Frame Dot must be instance of QrTagShape class.'); } $this->frameDot->size = $this->dot->markerSize ? $this->dot->markerSize : $this->dot->size; $this->frameDotImg = $this->frameDot->generate(); if (!$this->frame instanceof QrTagShape) { throw new Exception('Frame must be instance of QrTagShape class.'); } $this->frame->bgColorRGB = $this->bgColorRGB; $this->frame->size = $this->dot->size; $this->frameImg = $this->frame->generate(); $this->cols = count($this->data[0]); $this->rows = count($this->data); $this->width = $this->cols * $this->dot->size; $this->height = $this->rows * $this->dot->size; $this->image = imagecreatetruecolor($this->width, $this->height); // transparent imagefilledrectangle($this->image, 0, 0, $this->width, $this->height, imagecolorallocate($this->image, $this->bgColorRGB[0], $this->bgColorRGB[1], $this->bgColorRGB[2])); }
public function actionGenerateTransQr() { self::registerImageQrAutoloader(); Yii::import('ext.qr.phpqrcode.qrlib', true); $model = Qr::model()->findByPk(Yii::app()->session['qr_id']); $size = isset($_GET['size']) ? intval($_GET['size']) : 0; $x = isset($_GET['x']) ? intval($_GET['x']) : 0; $y = isset($_GET['y']) ? intval($_GET['y']) : 0; $imgTmp = imagecreatefromstring(file_get_contents(Yii::app()->session['trans_qr_code_file'])); $img = imagecreatetruecolor(imagesx($imgTmp), imagesy($imgTmp)); imagefill($img, 0, 0, imagecolorallocatealpha($img, 255, 255, 255, 127)); imagecopymerge($img, $imgTmp, 0, 0, 0, 0, imagesx($imgTmp), imagesy($imgTmp), 100); imagedestroy($imgTmp); imagesavealpha($img, true); $size = $size < 100 ? min(array(imagesx($img), imagesy($img))) : $size; $data = QRCode::text($model->tag_url, false, 'Q'); $data = array_map('str_split', $data); array_walk_recursive($data, 'intval'); $qr = new \Madlogics\VisualQr($img); $qr->setData($data); $qr->setSize($size)->setX($x)->setY($y); header('Content-Type: image/png'); $im2 = $qr->render()->getImageQrIm(); imagepng($im2); imagepng($im2, $model->image_path); exit; }