src/qrencode.php
public static function svg($text, $elemId = false, $outFile = false, $level = QR_ECLEVEL_L, $width = false, $size = false, $margin = 4, $compress = false) 
        {
            $enc = QRencode::factory($level, 1, 0);
            $tab_src = $enc->encode($text, false);
            $area = new QRsvgOutput($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;
                    }
                }
            }
            
            $svg = '<svg xmlns="http://www.w3.org/2000/svg"
            xmlns:xlink="http://www.w3.org/1999/xlink"
            version="1.1"
            baseProfile="full"
            viewBox="'.(-$margin).' '.(-$margin).' '.($area->getWidth()+($margin*2)).' '.($area->getWidth()+($margin*2)).'" 
            width="'.$width.'"
            height="'.$width.'"
            id="'.$elemId.'">'."\n";
   
            $svg .= $area->getRawSvg().'</svg>';
   
            if ($outFile !== false) {
                $xmlPreamble = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'."\n";
                $svgContent = $xmlPreamble.$svg;
                
                if ($compress === true) {
                    file_put_contents($outFile, gzencode($svgContent));
                } else {
                    file_put_contents($outFile, $svgContent);
                }
            }
            
            return $svg;
        }
public static function svg($text, $elemId = false, $outFile = false, $level = QR_ECLEVEL_L, $width = false, $size = false, $margin = 4, $compress = false) 
        {
            $enc = QRencode::factory($level, 1, 0);
            $tab_src = $enc->encode($text, false);
            $area = new QRsvgOutput($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;
                    }
                }
            }
            
            $svg = '<svg xmlns="http://www.w3.org/2000/svg"
            xmlns:xlink="http://www.w3.org/1999/xlink"
            version="1.1"
            baseProfile="full"
            viewBox="'.(-$margin).' '.(-$margin).' '.($area->getWidth()+($margin*2)).' '.($area->getWidth()+($margin*2)).'" 
            width="'.$width.'"
            height="'.$width.'"
            id="'.$elemId.'">'."\n";
   
            $svg .= $area->getRawSvg().'</svg>';
   
            if ($outFile !== false) {
                $xmlPreamble = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'."\n";
                $svgContent = $xmlPreamble.$svg;
                
                if ($compress === true) {
                    file_put_contents($outFile, gzencode($svgContent));
                } else {
                    file_put_contents($outFile, $svgContent);
                }
            }
            
            return $svg;
        }
public static function svg ( $ text , $ elemId = false , $ outFile = false , $ level = QR_ECLEVEL_L , $ width = false , $ size = false , $ margin = 4 , $ compress = false ) { $ enc = QRencode :: factory ( $ level , 1 , 0 ) ; $ tab_src = $ enc -> encode ( $ text , false ) ; $ area = new QRsvgOutput ( $ 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 ; } } } $ svg = '<svg xmlns="http://www.w3.org/2000/svg"
            xmlns:xlink="http://www.w3.org/1999/xlink"
            version="1.1"
            baseProfile="full"
            viewBox="' . ( - $ margin ) . ' ' . ( - $ margin ) . ' ' . ( $ area -> getWidth ( ) + ( $ margin * 2 ) ) . ' ' . ( $ area -> getWidth ( ) + ( $ margin * 2 ) ) . '" 
            width="' . $ width . '"
            height="' . $ width . '"
            id="' . $ elemId . '">' . "\n" ; $ svg .= $ area -> getRawSvg ( ) . '</svg>' ; if ( $ outFile !== false ) { $ xmlPreamble = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n" ; $ svgContent = $ xmlPreamble . $ svg ; if ( $ compress === true ) { file_put_contents ( $ outFile , gzencode ( $ svgContent ) ) ; } else { file_put_contents ( $ outFile , $ svgContent ) ; } } return $ svg ; }
Creates SVG with QR-Code.
Simple helper function to create QR-Code SVG with one static call.
@param String $text text string to encode
@param Boolean $elemId (optional) target SVG tag id attribute, if __false__ SVG tag with auto id will be created
@param String $outfile (optional) output file name, when __false__ file is not saved
@param Integer $level (optional) error correction level __QR_ECLEVEL_L__, __QR_ECLEVEL_M__, __QR_ECLEVEL_Q__ or __QR_ECLEVEL_H__
@param Integer $width (optional) SVG 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 $compress (optional) if __true__, compressed SVGZ (instead plaintext SVG) is saved to file
@return String containing SVG tag
Creates SVG with QR - Code . Simple helper function to create QR - Code SVG with one static call .