QR Code Generator v1.0.1

API Reference

webpatser@dev: ~/qr-code/1.0.1 $ cat api-reference.md

API Reference - QR Code Generator v1.0.1

Complete API documentation for all QR code types, methods, and configuration options. All examples include live QR code generation.

Core QR Code Types

QR_Text

Generate QR codes containing plain text or any string data.

Constructor

Parameters
  • $data (string): Text content to encode
Methods
  • png() - Generate PNG image data URI
  • svg() - Generate SVG markup
  • eps() - Generate EPS PostScript
API Text QR

Live Example

 
use QR_Code\Types\QR_Text;
 
// Basic usage
$qr = new QR_Text('Hello, API!');
$pngDataUri = $qr->png();
$svgMarkup = $qr->svg();
 
// With configuration
$qr->setSize(6)
->setMargin(4)
->setErrorCorrectionLevel('H');

QR_Url

Optimized for web URLs and links.

Constructor

Parameters
  • $url (string): Complete URL with protocol
URL Formats
API URL QR

GitHub Link

 
use QR_Code\Types\QR_Url;
 
$websiteQR = new QR_Url('https://example.com');
$localQR = new QR_Url('http://localhost:3000');
$emailQR = new QR_Url('mailto:[email protected]');
$phoneQR = new QR_Url('tel:+1-555-123-4567');

QR_EmailMessage

Create email composition QR codes with subject and body.

Constructor

Parameters
  • $email (string): Recipient email address
  • $message (string): Email body content
  • $subject (string): Email subject line
Output Format

Uses MATMSG format for maximum compatibility

API Email QR

Email Example

 
use QR_Code\Types\QR_EmailMessage;
 
$email = new QR_EmailMessage(
'[email protected]', // Recipient
'Hello from QR code!', // Body
'QR Code Contact' // Subject
);
 
$emailPng = $email->png();

QR_Phone & QR_Sms

Phone calls and SMS messaging QR codes.

QR_Phone

Phone Formats
  • +1-555-123-4567
  • (555) 123-4567
  • 5551234567
Phone QR

QR_Sms

Parameters
  • $phone - Target number
  • $message - SMS content
SMS QR
 
use QR_Code\Types\QR_Phone;
use QR_Code\Types\QR_Sms;
 
// Phone call QR code
$phoneQR = new QR_Phone('+1-555-123-4567');
 
// SMS with pre-filled message
$smsQR = new QR_Sms('+1-555-123-4567', 'Hello from QR!');

QR_WiFi

WiFi network credential sharing.

Constructor

Parameters
  • $ssid - Network name
  • $password - Network password
  • $security - Security type
Security Types
  • 'WPA' - WPA/WPA2 (most common)
  • 'WEP' - Legacy WEP
  • 'nopass' - Open network
WiFi QR

Demo Network

 
use QR_Code\Types\QR_WiFi;
 
// WPA protected network
$wifi = new QR_WiFi('MyHomeNetwork', 'secret123', 'WPA');
 
// Open network
$openWifi = new QR_WiFi('PublicWiFi', '', 'nopass');
 
// Guest network
$guestWifi = new QR_WiFi('Guest-Network', 'guest2023', 'WPA');

QR_VCard

Contact information sharing with vCard format.

Constructor

Required Classes
  • QR_Code\Types\vCard\Person
  • QR_Code\Types\vCard\Phone
  • QR_Code\Types\vCard\Address
Person Constructor
vCard QR

Contact Card

 
use QR_Code\Types\QR_VCard;
use QR_Code\Types\vCard\Person;
use QR_Code\Types\vCard\Phone;
use QR_Code\Types\vCard\Address;
 
// Create person
$person = new Person(
'John', // First name
'Doe', // Last name
'Mr.', // Title
'[email protected]', // Email
'Example Corp', // Organization
'Software Engineer' // Job title
);
 
// Add phone numbers
$workPhone = new Phone('+1-555-123-4567', 'WORK');
$mobilePhone = new Phone('+1-555-987-6543', 'CELL');
 
// Add address
$workAddress = new Address(
'123 Business St', // Street
'Tech City', // City
'TC', // State
'12345', // ZIP
'USA' // Country
);
 
// Create vCard
$vcard = new QR_VCard($person, [$workPhone, $mobilePhone], [$workAddress]);

Configuration Methods

All QR code types inherit configuration methods from AbstractGenerator:

Size & Quality

  • setSize(int $size)
    1-50, default: 3
  • setMargin(int $margin)
    0-20, default: 4
  • setErrorCorrectionLevel(string $level)
    'L', 'M', 'Q', 'H'

Colors & Output

  • setBackColor(int $color)
    RGB color value
  • setForeColor(int $color)
    RGB color value
  • setOutfile(string $path)
    Save to file
 
use QR_Code\Types\QR_Text;
 
$qr = new QR_Text('Configured QR Code');
 
// Chain configuration methods
$qr->setSize(8) // Large size
->setMargin(6) // Wide margin
->setErrorCorrectionLevel('H') // High error correction
->setBackColor(0xFFFFFF) // White background
->setForeColor(0x000000); // Black foreground
 
$result = $qr->png();

Error Correction Levels

Level
Recovery %
Use Case
Performance
L ~7% Clean environments, digital displays
Fastest
M ~15% General purpose, most applications
Fast
Q ~25% Industrial, outdoor use
Moderate
H ~30% Harsh conditions, may be damaged
Slower

Utility Classes

Tools Class

 
use QR_Code\Util\Tools;
 
// Performance optimization
Tools::buildCache(); // Enable caching for speed
Tools::clearCache(); // Clear generated cache
 
// Cleanup
Tools::clearTemporaryQRCodes(); // Remove temp files

ImageEngine Detection

 
use QR_Code\Enums\ImageEngine;
 
// Check what's available
$engines = ImageEngine::getAvailable();
// Returns: [ImageEngine::Imagick, ImageEngine::GD, ImageEngine::None]
 
// Get best engine
$best = ImageEngine::detectBest();
echo "Using: " . $best->name; // "Imagick" or "GD"

ArrayOptimizer

 
use QR_Code\Util\ArrayOptimizer;
 
// Matrix operations for advanced users
$matrix = $qr->getMatrix();
$compressed = ArrayOptimizer::compressMatrix($matrix);
$restored = ArrayOptimizer::decompressMatrix($compressed, 25);
 
// Validation
$isValid = ArrayOptimizer::validateMatrix($matrix);

Error Handling

 
use QR_Code\Types\QR_Text;
 
try {
$qr = new QR_Text(''); // This will throw an exception
$result = $qr->png();
} catch (\InvalidArgumentException $e) {
echo "Invalid input: " . $e->getMessage();
} catch (\Exception $e) {
echo "QR generation failed: " . $e->getMessage();
}

Performance Considerations

  • Enable caching for repeated QR codes: Tools::buildCache()
  • Use size 3-6 for optimal performance vs. quality balance
  • Choose error correction level based on environment
  • Install ImageMagick for ~40% better performance than GD
  • Reuse configuration when generating multiple similar QR codes

Return Values

Output Methods

  • png() - Returns complete data URI: "data:image/png;base64,iVBORw0KGgoAAAA..."
  • svg() - Returns SVG markup as string
  • eps() - Returns EPS PostScript as string

All methods return ready-to-use output - no additional encoding needed!

This completes the API reference for QR Code Generator v1.0.1. All methods are performance-optimized and production-ready.