<?php

/**
 * Example 007 - Use structured append and arrange the created codes using GD Lib
 *
 * "Structured append" enables you to distribute content over multiple QR Codes
 * (up to 16 ones). Information stored in multiple QR Codes can be reconstructed
 * as single data set, the scanning sequence doesn't matter.
 *
 * ATTENTION: Most mobile phone QR Code readers do not support "stuctured append"
 *
 * NOTE: "QR Code" is registered trademarks of DENSO WAVE INCORPORATED in Japan
 *       and other countries.
 *
 *
 * <b>de: Beispiel 007 - Nutzung von "stuctured append" und neu arrangieren der
 *    Codes mittels GD Lib</b>
 *
 * "Stuctured append" gibt Ihnen die Möglichkeit den Inhalt auf mehrere QR-Codes
 * zu verteilen (bis zu 16 Stück). Die in mehreren QR-Codes gespeicherten
 * Informationen werden dabei als zusammenhängender Datensatz zurückgegeben, die
 * Scanning-Reihenfolge ist dabei unwichtig.
 *
 * HINWEIS: "QR Code" ist eine von DENSO WAVE INCORPORATED in Japan und anderen
 *          Ländern eingetragene Marke.
 *
 *
 * PHP version 5
 *
 * LICENSE: This file is NOT free software. Try to contact the author(s) in
 *          doubt. Copyright injuries will be prosecuted!
 *
 * @copyright 2008-2010, EVERESTAH Ltd. & Co. KG
 * @link http://www.wikipedia.org/wiki/QR_Code
 * @link http://qrserver.com
 * @link http://goQR.me
 * @link http://www.bctester.de Free Barcode Reader for MS Windows
 * @link http://www.i-nigma.mobi Free QR Code Reader for mobile phones
 * @link http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=43655
 * @link http://www.denso-wave.com/qrcode/aboutqr-e.html
 */

//show source?
if (!empty($_GET["showsource"])) {
  
header("Content-Type: text/html; charset=UTF-8");
  
highlight_file(__FILE__);
  die();
}




//de: Importieren der benötigten Klasse
require_once "./class.qrcode_create.inc.php";


//en: Create object
//de: Objekt erstellen
$qr = new qrcode_create();


//en: Set input which will be written into the QR Code
//de: Setzen den Inhalts, welcher in den QR Code geschrieben werden soll.
$qr->setInput("Hello World! I am a text divided into several QR Codes using"
             
."structured append. Cool feature, isn't it? Example 123456789 "
             
."Example 123456789 Example 123456789 Example 123456789");


//en: Set the edge length to 350 pixels
//de: Setzen der Kantenlänge auf 350 Pixel
$edgelength 350;
$qr->setEdgeLength($edgelength);



//en: Hint: Whenever qrcode_create::create() is called, the currently set data,
//          color and stuff will be used to store the QR Code in memory
//          (overwriting eventually older ones). Therefore, it is easily
//          possible to change the data and call qrcode_create::create() again
//          to get a new QR Code, without having to work with multiple objects.
//de: Tipp: Wann immer qrcode_create::create() aufgerufen wird, werden die
//          aktuell gesetzten Daten, Farben etc. dazu verwendet, den QR Code im
//          Speicher abzulegen (ein ggf. vorher erstellter Code wird dabei
//          überschrieben). Daher ist es ohne Weiteres möglich, Daten zu
//          ändern und anschließend einfach nochmals qrcode_create::create()
//          aufzurufen, um einen anderen QR Code zu erhalten, ohne mit mehreren
//          Objekten arbeiten zu müssen.


//en: Create a GD image object in wich the QR Codes to create are fitting in
//de: Erstellen eines GD Image-Objekts, in welches die zu erstellenden QR Codes
//    inkl. Rand hineinpassen
$final_image imagecreate(//x
                           
$edgelength,
                           
//y
                           
$edgelength);



//en: Store the given Text into three QR Codes using structured append. The
//    actual text is automatically splitted as evenly as possible on various
//    Codes.
//de: Speichern des Textes in drei QR Codes mittels "structured append". Der
//    vorhandene Text wird dabei automatisch möglichst gleichmäßig auf die
//    verschiedenen Grafiken verteilt.


//en: Create Code 1/3, get the GD Library Image object afterwards (i.e. the
//    QR Code image) and copy it into the target image.
//de: Code 1/3 erstellen, anschließend das GD Library Bildobjekt (also die
//    QR Code Grafik) abholen und in das Zielbild kopieren.
$qr->create(13);
$temp $qr->img_returnGd();
imagecopy(//output resource
          
$final_image,
          
//source resource
          
$temp,
          
//x-coordinate of destination point
          
0,
          
//y-coordinate of destination point
          
0,
          
//x-coordinate of source point
          
0,
          
//y-coordinate of source point
          
0,
          
//source width
          
imagesx($temp),
          
//source height
          
imagesy($temp));


//en: Create Code 2/3, get the GD Library Image object afterwards (i.e. the
//    QR Code image) and copy it into the target image.
//de: Code 2/3 erstellen, anschließend das GD Library Bildobjekt (also die QR
//    Code Grafik) abholen und in das Zielbild kopieren.
$qr->create(23);
$temp $qr->img_returnGd();
imagecopy(//output resource
          
$final_image,
          
//source resource
          
$temp,
          
//x-coordinate of destination point
          
$edgelength,
          
//y-coordinate of destination point
          
0,
          
//x-coordinate of source point
          
0,
          
//y-coordinate of source point
          
0,
          
//source width
          
imagesx($temp),
          
//source height
          
imagesy($temp));


//en: Create Code 3/3, get the GD Library Image object afterwards (i.e. the
//    QR Code image) and copy it into the target image.
//de: Code 3/3 erstellen, anschließend das GD Library Bildobjekt (also die QR
//    Code Grafik) abholen und in das Zielbild kopieren.
$qr->create(33);
$temp $qr->img_returnGd();
imagecopy(//output resource
          
$final_image,
          
//source resource
          
$temp,
          
//x-coordinate of destination point
          
$edgelength 2,
          
//y-coordinate of destination point
          
0,
          
//x-coordinate of source point
          
0,
          
//y-coordinate of source point
          
0,
          
//source width
          
imagesx($temp),
          
//source height
          
imagesy($temp));


//en: Display and clean up
//de: Ausgeben und aufräumen
if (PHP_SAPI !== "cli") { //constant out of the PHP environment
  
header("Content-Type: image/png"); //we are running on a webserver, send needed headers
}
imagepng($final_image);
imagedestroy($final_image);

?>