Examples Menu
Standard API Basics - Quick Start
001 PNG Output Browser
002 Using outputed PNG
003 Parametrised PNG generator...
004 ... and how to use it
005 PNG saved to file
006 Configuring ECC level
007 Configuring pixel size
008 Configuring frame size
010 Using merged lib version
020 Content - Phone Number
021 Content - SMS App
022 Content - Email simple
023 Content - Email extended
024 Content - Skype call
025 Content - Business Card, simple
026 Content - Business Card, detailed
027 Content - Business Card, photo
Plugins API Basics - Quick Start
100 --- ToDo ---
Standard API - Vector Graphics
201 SVG basic output
202 SVG confguring output
203 SVG save to file
204 Compressed SVGZ save support
211 CANVAS basic
212 CANVAS rendered on custom tag
Plugins API - Vector Graphics
300 --- ToDo ---
Standard API - Debug & Custom Dev
701 Text output
702 Text output - ASCII ART
703 Raw Code output
704 Raw Code debug
711 Custom GD2 JPEG renderer
712 Custom GD2 debug renderer
721 Vector debug - areas
722 Vector debug - edges
723 Vector debug - paths renderer
Plugins API - Debug & Custom Dev
800 --- ToDo ---

Result
Sourcecode
example_711_custom_gd_output.php
<?php

    
include('../lib/full/qrlib.php');
    include(
'config.php');

    
// custom code rendering with GD2
    
    // WARNING!!! this is 'bad' example:
    // - JPEG is bad choice for QR-Codes (loosy, artifacts...)
    // - blue is bad choise for FG color (should make hi contrast with BG color)

    
$codeContents = '12345';
    
$tempDir = EXAMPLE_TMP_SERVERPATH;
    
$fileName = '711_test_custom.jpg';
    
$outerFrame = 4;
    
$pixelPerPoint = 5;
    
$jpegQuality = 95;
    
    
// generating frame
    
$frame = QRcode::text($codeContents, false, QR_ECLEVEL_M);
    
    
// rendering frame with GD2 (that should be function by real impl.!!!)
    
$h = count($frame);
    
$w = strlen($frame[0]);
    
    
$imgW = $w + 2*$outerFrame;
    
$imgH = $h + 2*$outerFrame;
    
    
$base_image = imagecreate($imgW, $imgH);
    
    
$col[0] = imagecolorallocate($base_image,255,255,255); // BG, white 
    
$col[1] = imagecolorallocate($base_image,0,0,255);     // FG, blue

    
imagefill($base_image, 0, 0, $col[0]);

    for(
$y=0; $y<$h; $y++) {
        for(
$x=0; $x<$w; $x++) {
            if (
$frame[$y][$x] == '1') {
                
imagesetpixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); 
            }
        }
    }
    
    
// saving to file
    
$target_image = imagecreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
    
imagecopyresized(
        
$target_image, 
        
$base_image, 
        
0, 0, 0, 0, 
        
$imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH
    
);
    
imagedestroy($base_image);
    
imagejpeg($target_image, $tempDir.$fileName, $jpegQuality);
    
imagedestroy($target_image);

    
// displaying
    
echo '<img src="'.EXAMPLE_TMP_URLRELPATH.$fileName.'" />';