QR Code Generator v1.0.1
API Reference
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 URIsvg()- Generate SVG markupeps()- Generate EPS PostScript
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
https://example.comhttp://localhost:8000mailto:[email protected]tel:+1234567890
GitHub Link
use QR_Code\Types\QR_Url; $websiteQR = new QR_Url('https://example.com');$localQR = new QR_Url('http://localhost:3000');$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
Email Example
use QR_Code\Types\QR_EmailMessage; $email = new QR_EmailMessage( '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-45675551234567
QR_Sms
Parameters
- $phone - Target number
- $message - SMS content
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
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\PersonQR_Code\Types\vCard\PhoneQR_Code\Types\vCard\Address
Person Constructor
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 '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: 3setMargin(int $margin)
0-20, default: 4setErrorCorrectionLevel(string $level)
'L', 'M', 'Q', 'H'
Colors & Output
setBackColor(int $color)
RGB color valuesetForeColor(int $color)
RGB color valuesetOutfile(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 | |
| M | ~15% | General purpose, most applications | |
| Q | ~25% | Industrial, outdoor use | |
| H | ~30% | Harsh conditions, may be damaged |
Utility Classes
Tools Class
use QR_Code\Util\Tools; // Performance optimizationTools::buildCache(); // Enable caching for speedTools::clearCache(); // Clear generated cache // CleanupTools::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.