PHP Classes

File: qrcode-display.php

Recommend this page to a friend!
  Classes of Maik Greubel   PHP QR Code Generator   qrcode-display.php   Download  
File: qrcode-display.php
Role: Example script
Content type: text/plain
Description: demo for displaying image in browser
Class: PHP QR Code Generator
Generate QR Code images in pure PHP
Author: By
Last change: Make it more flexible for unicode characters
Date: 9 years ago
Size: 1,362 bytes
 

Contents

Class file image Download
<?php
set_include_path
( get_include_path () . PATH_SEPARATOR . './src' );

require
'ErrorHandler.php';
require
'SimpleLogger.php';

$data = "";
$width = 256;
$height = 256;
$quality = 50;

if (isset (
$_GET ['data'] ))
{
 
$data = urldecode($_GET['data']);
 
$data = html_entity_decode( $data, ENT_QUOTES, 'UTF-8' );
}

if (isset(
$_GET['w']))
{
 
$width = intval($_GET['w']);
  if(
$width < 32 || $width > 256)
   
$width = 256;
}

if (isset(
$_GET['h']))
{
 
$height = intval($_GET['h']);
  if(
$height < 32 || $height > 256)
   
$height = 256;
}

if (isset(
$_GET['q']))
{
 
$quality = intval($_GET['q']);
  if(
$quality < 10 || $quality > 100)
  {
   
$quality = 50;
  }
}

if (
$data)
{
  require_once
'QRErrorCorrectLevel.php';
  require_once
'QRCode.php';
  require_once
'QRCodeImage.php';
 
  try
  {
   
$code = new QRCode ( - 1, QRErrorCorrectLevel::H );
   
$code->addData ( $data );
   
$code->make ();
   
   
$img = new QRCodeImage ( $code, $width, $height, $quality );
   
$img->draw ();
   
$imgdata = $img->getImage ();
   
$img->finish ();
   
    if (
$imgdata)
    {
     
header ( 'Content-Type: image/jpeg' );
     
header ( 'Content-Length: ' . strlen ( $imgdata ) );
      echo
$imgdata;
    }
  }
  catch (
Exception $ex )
  {
   
SimpleLogger::logException($ex);
  }
}