Example #1
0
 /**
  * @covers Image\Draw\Qrcode::getBarcodeArray
  */
 public function testGetBarcodeArray()
 {
     $this->object->setText('test');
     $this->assertInternalType('array', $this->object->getBarcodeArray());
 }
 private function errorCorrection()
 {
     if (DEBUG && DEBUG_LEVEL & EQR_EC) {
         $debug = true;
     } else {
         $debug = false;
     }
     //Generator polynomial for Reed-salomon error correction codewords
     $ecPolynomial[7] = array(0, 87, 229, 146, 149, 238, 102, 21);
     $ecPolynomial[10] = array(0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45);
     $ecPolynomial[13] = array(0, 74, 152, 176, 100, 86, 100, 106, 104, 130, 218, 206, 140, 78);
     $ecPolynomial[15] = array(0, 8, 183, 61, 91, 202, 37, 51, 58, 58, 237, 140, 124, 5, 99, 105);
     $ecPolynomial[16] = array(0, 120, 104, 107, 109, 102, 161, 76, 3, 91, 191, 147, 169, 182, 194, 255, 120);
     $ecPolynomial[17] = array(0, 43, 139, 206, 78, 43, 239, 123, 206, 214, 147, 24, 99, 150, 39, 243, 163, 136);
     $ecPolynomial[18] = array(0, 215, 234, 158, 94, 184, 97, 118, 170, 79, 187, 152, 148, 252, 179, 5, 98, 96, 153);
     $ecPolynomial[20] = array(0, 17, 60, 79, 50, 61, 163, 26, 187, 202, 180, 221, 225, 83, 239, 156, 164, 212, 212, 188, 190);
     $ecPolynomial[22] = array(0, 210, 171, 247, 242, 93, 230, 14, 109, 221, 53, 200, 74, 8, 172, 98, 80, 219, 134, 160, 105, 165, 231);
     $ecPolynomial[24] = array(0, 229, 121, 135, 48, 211, 117, 251, 126, 159, 180, 169, 152, 192, 226, 228, 218, 111, 0, 117, 232, 87, 96, 227, 21);
     $ecPolynomial[26] = array(0, 173, 125, 158, 2, 103, 182, 118, 17, 145, 201, 111, 28, 165, 53, 161, 21, 245, 142, 13, 102, 48, 227, 153, 145, 218, 70);
     $ecPolynomial[28] = array(0, 168, 223, 200, 104, 224, 234, 108, 180, 110, 190, 195, 147, 205, 27, 232, 201, 21, 43, 245, 87, 42, 195, 212, 119, 242, 37, 9, 123);
     $ecPolynomial[30] = array(0, 41, 173, 145, 152, 216, 31, 179, 182, 50, 48, 110, 86, 239, 96, 222, 125, 42, 173, 226, 193, 224, 130, 156, 37, 251, 216, 238, 40, 192, 180);
     $this->ecCw = Qrcode::getECTable($this->version, $this->errorLevel, EC_CW);
     $this->genPoly = $ecPolynomial[$this->ecCw];
     $this->initExp1 = Qrcode::getECTable($this->version, $this->errorLevel, CW_BLCK1) - 1;
     $this->initExp2 = Qrcode::getECTable($this->version, $this->errorLevel, CW_BLCK2) - 1;
     $this->ecBlck1 = Qrcode::getECTable($this->version, $this->errorLevel, BLOCK1);
     $this->ecBlck2 = Qrcode::getECTable($this->version, $this->errorLevel, BLOCK2);
     $index = 0;
     if ($debug) {
         printf("Error Correction Codewords %d<br>Block 1 Number of Error " . "Correction Blocks %d<br>Block 2 Number of Error Correction Blocks %d<br>", $this->ecCw, $this->ecBlck1, $this->ecBlck2);
     }
     $data1Len = Qrcode::getECTable($this->version, $this->errorLevel, CW_BLCK1) - $this->ecCw;
     for ($i = 1; $i <= $this->ecBlck1; $i++) {
         $dataBlck1[$i] = substr($this->strEncoded, $index, CW_BITS * $data1Len);
         if (isset($mssgPoly)) {
             unset($mssgPoly[$i]);
         }
         $mssgPoly[$i] = new cIPoly();
         if (isset($ecPoly1)) {
             unset($ecPoly1[$i]);
         }
         $ecPoly1[$i] = new cAPoly();
         //generate ecc polynomial
         for ($k = 0; $k < count($ecPolynomial[$this->ecCw]); $k++) {
             $ecPoly1[$i]->addTerm(new cATerm($ecPolynomial[$this->ecCw][$k], $this->initExp1 - $k));
         }
         $exp = $this->initExp1;
         //generate message polynomial
         for ($j = 0; $j < CW_BITS * $data1Len; $j += CW_BITS) {
             $coeff = bindec(substr($dataBlck1[$i], $j, CW_BITS));
             $mssgPoly[$i]->addTerm(new cITerm($coeff, $exp));
             $exp--;
         }
         if ($debug) {
             print "Generator polynomial (Block 1) " . $ecPoly1[$i] . "<br>";
             printf("Data Block 1, %d : <br>%s<br>Message polynomial= <br>%s<br>", $i, wordwrap($dataBlck1[$i], 64, "<br>", true), $mssgPoly[$i]);
         }
         $ecBlck1[$i] = $this->computeEC($ecPoly1[$i], $mssgPoly[$i]);
         if ($debug) {
             printf("Error Correction Block 1, %d : <br>%s<br>", $i, wordwrap($ecBlck1[$i], 64, "<br>", true));
         }
         $index += CW_BITS * $data1Len;
     }
     $data2Len = Qrcode::getECTable($this->version, $this->errorLevel, CW_BLCK2) - $this->ecCw;
     if ($this->ecBlck2 > 0) {
         for ($i = 1; $i <= $this->ecBlck2; $i++) {
             $dataBlck2[$i] = substr($this->strEncoded, $index, CW_BITS * $data2Len);
             unset($mssgPoly[$i]);
             $mssgPoly[$i] = new cIPoly();
             unset($ecPoly2[$i]);
             $ecPoly2[$i] = new cAPoly();
             //generate ecc polynomial
             for ($k = 0; $k < count($ecPolynomial[$this->ecCw]); $k++) {
                 $ecPoly2[$i]->addTerm(new cATerm($ecPolynomial[$this->ecCw][$k], $this->initExp2 - $k));
             }
             $exp = $this->initExp2;
             //generate message polynomial
             for ($j = 0; $j < CW_BITS * $data2Len; $j += CW_BITS) {
                 $coeff = bindec(substr($dataBlck2[$i], $j, CW_BITS));
                 $mssgPoly[$i]->addTerm(new cITerm($coeff, $exp));
                 $exp--;
             }
             if ($debug) {
                 print "Generator polynomial (Block 2) " . $ecPoly2[$i] . "<br>";
                 printf("Data Block 2, %d : <br>%s<br>Message polynomial= <br>%s<br>", $i, wordwrap($dataBlck2[$i], 64, "<br>", true), $mssgPoly[$i]);
             }
             $ecBlck2[$i] = $this->computeEC($ecPoly2[$i], $mssgPoly[$i]);
             if ($debug) {
                 printf("Error Correction Block 2, %d : <br>%s<br>", $i, wordwrap($ecBlck2[$i], 64, "<br>", true));
             }
             $index += CW_BITS * $data2Len;
         }
     }
     $finalSeq = "";
     if ($data1Len >= $data2Len) {
         $dataLen = $data1Len;
     } else {
         $dataLen = $data2Len;
     }
     //generate final sequence
     for ($i = 0; $i < $dataLen; $i++) {
         for ($j = 1; $j <= $this->ecBlck1; $j++) {
             if ($i * CW_BITS + CW_BITS <= strlen($dataBlck1[$j])) {
                 $finalSeq .= substr($dataBlck1[$j], $i * CW_BITS, CW_BITS);
             }
         }
         for ($j = 1; $j <= $this->ecBlck2; $j++) {
             if ($i * CW_BITS + CW_BITS <= strlen($dataBlck2[$j])) {
                 $finalSeq .= substr($dataBlck2[$j], $i * CW_BITS, CW_BITS);
             }
         }
     }
     for ($i = 0; $i < $this->ecCw; $i++) {
         for ($j = 1; $j <= $this->ecBlck1; $j++) {
             $finalSeq .= substr($ecBlck1[$j], $i * CW_BITS, CW_BITS);
         }
         for ($j = 1; $j <= $this->ecBlck2; $j++) {
             $finalSeq .= substr($ecBlck2[$j], $i * CW_BITS, CW_BITS);
         }
     }
     //add reminder bits
     if ($this->remBits > 0) {
         $finalSeq .= sprintf("%0" . $this->remBits . "b", 0);
     }
     $this->finalSeq = $finalSeq;
     if ($debug) {
         printf("Final sequence: <br>%s<br>", wordwrap($this->finalSeq, 64, "<br>", true));
     }
 }
Example #3
0
<?php

include "phpqrcode/qrlib.php";
$bgcolor = 0x33cccc;
$fgcolor = 0x3333cc;
// Qrcode::png("http://www.crazyws.fr/"); // QrCode affiché à l'écran
// Qrcode::png("http://www.crazyws.fr/", "crazyws.png", "L", 4, 4); // QrCode enregistrer sous le nom de crazyws.png à la racine
Qrcode::svg("http://www.crazyws.fr/", "crazyws.svg", "L", 4, 4, false, $bgcolor, $fgcolor);
// QrCode enregistrer sous le nom de crazyws.svg à la racine
Example #4
0
<?php

/*code developed by:Sagar Bhattacharya
website:www.smogate.com,www.vyuuh.com
email:sagar13912@gmail.com

*/
$x = new Qrcode();
$x->_setname('Sagar');
$x->_setemail('*****@*****.**');
$y = array('http://google.com', 'http://www.smogate.com');
$x->_setlinks($y);
$x->_setphone('8744096752');
$x->_setaddress('YOUR ADDRESS');
$x->_settext('I am Sagar');
$x->_settimestamp();
$x->display();
class Qrcode
{
    private $name;
    private $email;
    private $timestamp;
    private $links = array();
    private $phone;
    private $address;
    private $Qrcode;
    private $text;
    private $error = false;
    public function _setname($name)
    {
        if (ctype_alpha($name)) {