public function encode($intext, $outfile = false) { $code = new wechat_qrcode_QRcode(); if ($this->eightbit) { $code->encodeString8bit($intext, $this->version, $this->level); } else { $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); } wechat_qrcode_QRtools::markTime('after_encode'); if ($outfile !== false) { file_put_contents($outfile, join("\n", wechat_qrcode_QRtools::binarize($code->data))); } else { return wechat_qrcode_QRtools::binarize($code->data); } }
public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037') { $barcode_array = array(); if (!is_array($mode)) { $mode = explode(',', $mode); } $eccLevel = 'L'; if (count($mode) > 1) { $eccLevel = $mode[1]; } $qrTab = wechat_qrcode_QRcode::text($code, false, $eccLevel); $size = count($qrTab); $barcode_array['num_rows'] = $size; $barcode_array['num_cols'] = $size; $barcode_array['bcode'] = array(); foreach ($qrTab as $line) { $arrAdd = array(); foreach (str_split($line) as $char) { $arrAdd[] = $char == '1' ? 1 : 0; } $barcode_array['bcode'][] = $arrAdd; } return $barcode_array; }
public function create($intext, $long_touch) { $mdl_image = app::get('image')->model('image'); if ($exits_image = $mdl_image->dump(md5($intext . $long_touch))) { return $exits_image; } $tmp_file = tempnam(TMP_DIR, 'qrcode'); wechat_qrcode_QRcode::png($intext, $tmp_file, 'L', 8, 4); list($w, $h, $type) = getimagesize($tmp_file); if ($long_touch) { //加入额外图像 $resize_tmp_file = tempnam(TMP_DIR, 'qrcode_resize'); $image_tool = vmc::singleton('image_tools_gd'); $image_tool->resize($tmp_file, $resize_tmp_file, $w, $h, $type, $w + 180, $h + 220, false, 20); $water_file = PUBLIC_DIR . '/misc/long_touch.gif'; list($w_w, $w_h, $w_type) = getimagesize($water_file); $warermark_set = array('wm_opacity' => 100, 'watermark_width' => $w_w, 'watermark_height' => $w_h, 'type' => $w_type, 'src_width' => $w + 180, 'src_height' => $h + 180, 'dest_x' => ($w + 180 - 120) / 2, 'dest_y' => $h + 50); $image_tool->watermark($resize_tmp_file, $water_file, $warermark_set); } $storager = new base_storager(); if ($long_touch) { list($url, $ident, $storage) = explode('|', $storager->save_upload($resize_tmp_file, 'image', '', $msg, '.png')); } else { list($url, $ident, $storage) = explode('|', $storager->save_upload($tmp_file, 'image', '', $msg, '.png')); } $tmp_qrcode_image = array('image_id' => md5($intext . $long_touch), 'storage' => $storage, 'image_name' => 'TMP_QRCODE', 'ident' => $ident, 'url' => $url, 'width' => $w, 'height' => $h, 'last_modified' => time()); $mdl_image->save($tmp_qrcode_image); unlink($tmp_file); if ($long_touch) { unlink($resize_tmp_file); } return $tmp_qrcode_image; }