本文整理汇总了PHP中QRcode::jscanvasincluded方法的典型用法代码示例。如果您正苦于以下问题:PHP QRcode::jscanvasincluded方法的具体用法?PHP QRcode::jscanvasincluded怎么用?PHP QRcode::jscanvasincluded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRcode
的用法示例。
在下文中一共展示了QRcode::jscanvasincluded方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: canvas
/**
* Creates Html+JS code to draw QR-Code with HTML5 Canvas.
* Simple helper function to create QR-Code array with one static call.
*
* @param String $text
* text string to encode
* @param String $elemId
* (optional) target Canvas tag id attribute, if __false__ Canvas tag with auto id will be created
* @param Integer $level
* (optional) error correction level __QR_ECLEVEL_L__, __QR_ECLEVEL_M__, __QR_ECLEVEL_Q__ or __QR_ECLEVEL_H__
* @param Integer $width
* (optional) CANVAS element width (sam as height)
* @param Integer $size
* (optional) pixel size, multiplier for each 'virtual' pixel
* @param Integer $margin
* (optional) code margin (silent zone) in 'virtual' pixels
* @param Boolean $autoInclude
* (optional) if __true__, required qrcanvas.js lib will be included (only once)
* @return String containing JavaScript creating the code, Canvas element (when $elemId is __false__) and script tag with required lib (when $autoInclude is __true__ and not yet included)
*/
public static function canvas($text, $elemId = false, $level = QR_ECLEVEL_L, $width = false, $size = false, $margin = 4, $autoInclude = false)
{
$html = '';
$extra = '';
if ($autoInclude) {
if (!self::$jscanvasincluded) {
self::$jscanvasincluded = true;
echo '<script type="text/javascript" src="qrcanvas.js"></script>';
}
}
$enc = QRencode::factory($level, 1, 0);
$tab_src = $enc->encode($text, false);
$area = new QRcanvasOutput($tab_src);
$area->detectGroups();
$area->detectAreas();
if ($elemId === false) {
$elemId = 'qrcode-' . md5(mt_rand(1000, 1000000) . '.' . mt_rand(1000, 1000000) . '.' . mt_rand(1000, 1000000) . '.' . mt_rand(1000, 1000000));
if ($width == false) {
if ($size !== false && $size > 0) {
$width = ($area->getWidth() + 2 * $margin) * $size;
} else {
$width = ($area->getWidth() + 2 * $margin) * 4;
}
}
$html .= '<canvas id="' . $elemId . '" width="' . $width . '" height="' . $width . '">Your browser does not support CANVAS tag! Please upgrade to modern version of FireFox, Opera, Chrome or Safari/Webkit based browser</canvas>';
}
if ($width !== false) {
$extra .= ', ' . $width . ', ' . $width;
}
if ($margin !== false) {
$extra .= ', ' . $margin . ', ' . $margin;
}
$html .= '<script>if(eval("typeof "+\'QRdrawCode\'+"==\'function\'")){QRdrawCode(QRdecompactOps(\'' . $area->getCanvasOps() . '\')' . "\n" . ', \'' . $elemId . '\', ' . $area->getWidth() . ' ' . $extra . ');}else{alert(\'Please include qrcanvas.js!\');}</script>';
return $html;
}