当前位置: 首页>>代码示例>>PHP>>正文


PHP QRcode::svg方法代码示例

本文整理汇总了PHP中QRcode::svg方法的典型用法代码示例。如果您正苦于以下问题:PHP QRcode::svg方法的具体用法?PHP QRcode::svg怎么用?PHP QRcode::svg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QRcode的用法示例。


在下文中一共展示了QRcode::svg方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: xml_highlight

<?php

include '../lib/full/qrlib.php';
include 'config.php';
// Saving SVG to file, demo with sourcecode preview
$tempDir = EXAMPLE_TMP_SERVERPATH;
$dataText = 'PHP QR Code :)';
$svgTagId = 'id-of-svg';
$saveToFile = '203_demo.svg';
// it is saved to file but also returned from function
$svgCode = QRcode::svg($dataText, false, $tempDir . $saveToFile);
$svgCodeFromFile = file_get_contents($tempDir . $saveToFile);
// taken from: http://php.net/manual/en/function.highlight-string.php by: Dobromir Velev
function xml_highlight($s)
{
    $s = preg_replace("|<([^/?])(.*)\\s(.*)>|isU", "[1]<[2]\\1\\2[/2] [5]\\3[/5]>[/1]", $s);
    $s = preg_replace("|</(.*)>|isU", "[1]</[2]\\1[/2]>[/1]", $s);
    $s = preg_replace("|<\\?(.*)\\?>|isU", "[3]<?\\1?>[/3]", $s);
    $s = preg_replace("|\\=\"(.*)\"|isU", "[6]=[/6][4]\"\\1\"[/4]", $s);
    $s = htmlspecialchars($s);
    $s = str_replace("\t", "&nbsp;&nbsp;", $s);
    $s = str_replace(" ", "&nbsp;", $s);
    $replace = array(1 => '0000FF', 2 => '0000FF', 3 => '800000', 4 => '00AA00', 5 => 'FF0000', 6 => '0000FF');
    foreach ($replace as $k => $v) {
        $s = preg_replace("|\\[" . $k . "\\](.*)\\[/" . $k . "\\]|isU", "<font color=\"#" . $v . "\">\\1</font>", $s);
    }
    return nl2br($s);
}
// tag output
echo $svgCodeFromFile;
echo '<br/>';
开发者ID:alaingab,项目名称:modx,代码行数:31,代码来源:example_203_saving_svg.php

示例2: qrtest

 public static function qrtest()
 {
     // Include only this file, remaining required files will be included from it
     if (!class_exists("qrstr", FALSE)) {
         require_once PATH_PHPQRCODE . "/qrlib.php";
     }
     //write code into file, Error corection lecer is lowest, L (one form: L,M,Q,H)
     //each code square will be 4x4 pixels (4x zoom)
     //code will have 2 code squares white boundary around
     if (1) {
         // Error correction level L : About 7% or less errors can be corrected.
         // Error correction level M : About 15% or less errors can be corrected.
         // Error correction level Q : About 25% or less errors can be corrected.
         // Error correction level H : About 30% or less errors can be corrected.
         $text = "http://www.nordita.org/guest/";
         $filetype = "png";
         // "png","svg","eps","txt"
         if (!in_array($filetype, array("png", "svg", "eps", "txt"))) {
             return FALSE;
         }
         $level = "H";
         // "L" (default) ,"M", "Q", "H"
         $pixelsize = 16;
         // pixel size of each code square
         $margin = 4;
         // boundary width in number of code squares
         $saveandprint = FALSE;
         // TRUE = save to file and display in browser; FALSE = save to file only; redundant if $outfile=FALSE
         $back_color = 0xffffff;
         $fore_color = 0x0;
         $cmyk = TRUE;
         $filename = "qrcode";
         $outfile = PATH_PHPQRCACHE . $filename . "." . $filetype;
         // full file path or FALSE (only output on screen)
         //$outfile      = FALSE;
         switch ($filetype) {
             case "png":
                 QRcode::png($text, $outfile, $level, $pixelsize, $margin, $saveandprint, $back_color, $fore_color);
                 break;
             case "eps":
                 QRcode::eps($text, $outfile, $level, $pixelsize, $margin, $saveandprint, $back_color, $fore_color, $cmyk);
                 break;
             case "svg":
                 QRcode::svg($text, $outfile, $level, $pixelsize, $margin, $saveandprint, $back_color, $fore_color);
                 break;
             case "txt":
                 QRcode::text($text, $outfile, $level, $pixelsize, $margin);
                 // black = "1", white = "0"
                 break;
         }
         // end switch
     }
     //same as above but outputs file directly into browser (with appr. header etc.)
     //all other settings are default
     //WARNING! it should be FIRST and ONLY output generated by script, otherwise
     //rest of output will land inside PNG binary, breaking it for sure
     if (0) {
         QRcode::png("PHP QR Code :)");
     }
     //show benchmark
     if (0) {
         QRtools::timeBenchmark();
     }
     //rebuild cache
     if (0) {
         QRtools::buildCache();
     }
     //code generated in text mode - as a binary table
     //then displayed out as HTML using Unicode block building chars :)
     if (0) {
         $qr = new QRencode();
         $tab = $qr->encode('PHP QR Code :)');
         QRspec::debug($tab, true);
     }
 }
开发者ID:,项目名称:,代码行数:75,代码来源:

示例3: dirname

 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */
include "qrlib.php";
if (isset($_REQUEST['svg'])) {
    echo QRcode::svg("stuff", false, QR_ECLEVEL_H, 10, 1);
    die;
}
echo "<h1>PHP QR Code</h1><hr/>";
//set it to writable location, a place for temp generated PNG files
$PNG_TEMP_DIR = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR;
//html PNG location prefix
$PNG_WEB_DIR = 'temp/';
//ofcourse we need rights to create temp dir
if (!file_exists($PNG_TEMP_DIR)) {
    mkdir($PNG_TEMP_DIR);
}
$filename = $PNG_TEMP_DIR . 'test.png';
//processing form input
//remember to sanitize user input in real-life solution !!!
$errorCorrectionLevel = 'L';
开发者ID:AmphibiaWeb,项目名称:amphibian-disease-tracker,代码行数:31,代码来源:index.php

示例4: generateQR

 public static function generateQR($uri, $data_path = null, $identifier_path = null)
 {
     /***
      * Generate a QR code from a string
      *
      * @param string $uri
      * @param string $data_path The path to the write directory
      * @param string $identifier_path An optional subdirectory for paths; makes loops easier
      * @returns array with the main results in "svg" and "raw" keys, with a Google fallback in the "url" key
      ***/
     try {
         require_once dirname(__FILE__) . '/../qr/qrlib.php';
         if (!class_exists('Stronghash')) {
             require_once dirname(__FILE__) . '/../core/stronghash/php-stronghash.php';
         }
         $salt = Stronghash::createSalt();
         $persistent = !empty($data_path);
         if (!$persistent) {
             $tmp_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR;
             if (!file_exists($tmp_dir)) {
                 if (!mkdir($tmp_dir)) {
                     # Could not write to temporary path
                     throw new Exception("Could not write to '{$tmp_dir}'");
                 }
             }
             $web_dir = 'temp/';
             $filename = $tmp_dir . sha1($salt) . '.png';
         } else {
             # Persistent file
             $file = $sha1($salt . $uri);
             if (substr($data_path, -1) != '/') {
                 $data_path .= DIRECTORY_SEPARATOR;
             }
             $full_path = empty($identifier_path) ? $data_path : $data_path . $identifier_path . DIRECTORY_SEPARATOR;
             if (!file_exists($full_path)) {
                 if (!mkdir($full_path)) {
                     # Could not write to the storage path
                     throw new Exception("Could not write to '{$full_path}'");
                 }
             }
             $filename = $full_path . $file . '.png';
         }
         $svg = QRcode::svg($uri, false, QR_ECLEVEL_H, 8, 1);
         if (function_exists('ImageCreate')) {
             QRcode::png($uri, $filename, QR_ECLEVEL_H, 8, 1);
         }
         $raw = base64_encode(file_get_contents($filename));
         $raw = 'data:image/png;base64,' . $raw;
         if (!$persistent) {
             unlink($filename);
         }
         # As a final option, get a URL fallback
         # https://developers.google.com/chart/infographics/docs/qr_codes?csw=1
         $url = 'https://chart.googleapis.com/chart?cht=qr&chs=500x500&chld=H&chl=' . $uri;
         return array('status' => true, 'uri' => $uri, 'svg' => $svg, 'raw' => $raw, 'url' => $url);
     } catch (Exception $e) {
         return array('status' => false, 'human_error' => 'Unable to generate QR code', 'error' => $e->getMessage(), 'uri' => $uri, 'identifier' => $identifier, 'persistent' => $persistent);
     }
 }
开发者ID:AmphibiaWeb,项目名称:amphibian-disease-tracker,代码行数:59,代码来源:login_functions.php

示例5: file_get_contents

if (ISQ::$social['googleplus']) {
    echo '<span onclick="window.open(\'https://plus.google.com/share?url=' . $encoded_shorturl . '\',\'_blank\',\'width=550,height=380\')" class="button social-button googleplus" title="Share on LinkedIn">' . file_get_contents('public/images/googleplus.svg') . '</span>';
}
?>
		
	</div>

	<?php 
if (ISQ::$general['qr']) {
    ?>
		<!-- QR code -->
		<h2><?php 
    yourls_e('QR code', 'isq_translation');
    ?>
</h2>
		<p><?php 
    yourls_e('Share your link with external devices', 'isq_translation');
    ?>
</p>
	
	<?php 
    // PHP QR Code is LGPL licensed
    include 'public/phpqrcode/qrlib.php';
    echo QRcode::svg($shorturl, 'url-qr-code', false, QR_ECLEVEL_L, '600');
}
?>

</div>

<?php 
include 'footer.php';
开发者ID:blacksector,项目名称:infinity-squared,代码行数:31,代码来源:result.php

示例6: strlen

<?php

include '../lib/full/qrlib.php';
include 'config.php';
// Compressed SVGZ support
$tempDir = EXAMPLE_TMP_SERVERPATH;
$dataText = 'PHP QR Code :)';
$svgTagId = 'id-of-svg';
$saveToFile = '204_demo.svgz';
$width = false;
// auto calculated
$size = false;
$margin = 4;
$compress = true;
// it is saved to file but also returned from function
$svgCode = QRcode::svg($dataText, false, $tempDir . $saveToFile, QR_ECLEVEL_L, $width, $size, $margin, $compress);
$svgCodeFromFile = file_get_contents($tempDir . $saveToFile);
$sizeOrig = strlen($svgCode);
$sizeGzip = strlen($svgCodeFromFile);
$saved = ($sizeOrig + 1 - $sizeGzip) / ($sizeOrig + 1) * 100;
echo '<b>Raw SVG size:</b> ' . $sizeOrig . ' B <br/>';
echo '<b>Compressed SVGZ size:</b> ' . $sizeGzip . ' B <br/>';
echo '<b>Saved:</b>: ' . number_format($saved, 3) . '%<br/>';
echo '<br/>Notice: your server need to be configured for SVGZ output - look into sfproxy.php<br/>';
echo '<iframe src="' . EXAMPLE_TMP_URLRELPATH . $saveToFile . '" style="width:98%;height:160px"></iframe>';
开发者ID:alaingab,项目名称:modx,代码行数:25,代码来源:example_204_saving_svgz.php

示例7:

<?php

include '../lib/full/qrlib.php';
// SVG file format support
$svgCode = QRcode::svg('PHP QR Code :)');
echo $svgCode;
开发者ID:alaingab,项目名称:modx,代码行数:6,代码来源:example_201_basic_svg.php

示例8: isset

$shorturl = isset($return['shorturl']) ? $return['shorturl'] : '';
$message = isset($return['message']) ? $return['message'] : '';
$title = isset($return['title']) ? $return['title'] : '';
$status = isset($return['status']) ? $return['status'] : '';
// URL encoded links used in the social sharing buttons
$encoded_shorturl = urlencode($shorturl);
$encoded_title = urlencode($title);
// QR code shenanigans
if (ISQ::$general['qr']) {
    // PHP QR Code is LGPL licensed
    include 'public/phpqrcode/qrlib.php';
    $qrContainerId = 'url-qr-code';
    $saveToFile = false;
    $imageWidth = 600;
    // in pixels
    $qrCode = QRcode::svg($url, $qrContainerId, $saveToFile, QR_ECLEVEL_L, $imageWidth);
}
?>

<div class="content">
	<!-- Error reporting -->
	<?php 
isset($error) ? $error : '';
?>

	<!-- Default output -->
	<h2><?php 
yourls_e('Your short URL', 'isq_translation');
?>
</h2>
开发者ID:abazapa,项目名称:infinity-squared,代码行数:30,代码来源:result.php

示例9: generateQr

 /**
  * @Route("/qrset/{qrset}/generate", name="generate_qr")
  * @Secure(roles="ROLE_USER")
  */
 public function generateQr(QrSet $qrset)
 {
     if ($this->getRequest()->get('quantity') == null) {
         echo 'Quantity is required';
         die;
     }
     $qrImages = array();
     $toFlush = array($qrset);
     for ($i = $qrset->getQrcodes()->count(); $i < $qrset->getQrcodes()->count() + (int) $this->getRequest()->get('quantity'); $i++) {
         // Create the QR Entity
         $qrCode = new QrCode();
         $qrCode->setQrset($qrset);
         $hash = hash_hmac('sha1', $qrset->getId() . '_' . $i, $qrset->getCourse()->getUser()->getPassword());
         $qrCode->setCode($hash);
         $this->container->get('doctrine')->getManager()->persist($qrCode);
         $toFlush[] = $qrCode;
         // Generate QR image based on the created entity
         $qrImage = array();
         $fileName = tempnam($this->container->getParameter("kernel.cache_dir"), 'qrimg');
         $link = $this->container->get('router')->generate('redeem', array('hash' => $qrCode->getCode()), true);
         \QRcode::svg($link, $fileName);
         $qrImage['link'] = $qrCode->getCode();
         $qrImage['svg'] = file_get_contents($fileName);
         $xml = simplexml_load_string($qrImage['svg']);
         $xml['width'] = 135;
         $xml['height'] = 135;
         $qrImage['svg'] = $xml->asXML();
         $qrImages[] = $qrImage;
     }
     $this->container->get('doctrine')->getManager()->persist($qrset);
     $this->container->get('doctrine')->getManager()->flush($toFlush);
     $html = $this->container->get('templating')->render('PixelbonusSiteBundle:QR:qr_template.html.twig', array('qrImages' => $qrImages));
     if ($this->getRequest()->get('html') == 'true') {
         return new Response($html);
     } else {
         $pdf = $this->container->get('knp_snappy.pdf')->getOutputFromHtml($html);
         return new Response($pdf, 200, array('Content-Type' => 'application/pdf', 'Content-Disposition' => sprintf('attachment;filename="%s.pdf"', 'qr')));
     }
 }
开发者ID:dspinellis,项目名称:pixelbonus,代码行数:43,代码来源:QRController.php

示例10: htmlspecialchars

<?php

// include php class for QR code generation
include './phpqrcode.php';
// get bitcoin address
$bitcoinaddress = htmlspecialchars($_GET["bitcoinaddress"]);
// output page
echo '<html><head><title>Bitcoin</title></head><body>';
echo '<div style="text-align:center;"><h1>Bitcoin</h1></div>';
echo '<p style="text-align:center;"><a href="bitcoin:' . $bitcoinaddress . '">bitcoin:' . $bitcoinaddress . '</a></p>';
echo '<p style="text-align:center;">';
QRcode::svg($bitcoinaddress, false, 'h', 5);
echo '</p>';
echo '<p style="text-align:center;">Information: <a href="https://www.bitcoin.org" target="_blank">bitcoin.org</a></p>';
echo '</body></html>';
开发者ID:tentwentyfour,项目名称:wordpress-shariff-wrapper,代码行数:15,代码来源:bitcoin.php


注:本文中的QRcode::svg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。