QR Code Generator v1.0.1
Interactive Examples
webpatser@dev:
~/qr-code/1.0.1
$ cat examples.md
Live Examples - QR Code Generator v1.0.1
Interactive examples showing all QR code types with real-time generation. Copy the code examples to get started!
Basic QR Code Types
Essential QR codes for everyday use:
Text QR Code
new QR_Text('Hello from QR Code!')
URL QR Code
new QR_Url('https://github.com/...')
Email QR Code
new QR_EmailMessage(...)
Communication QR Codes
QR codes for phone calls, SMS, and contact information:
Phone Call
new QR_Phone('+1-555-123-4567')
SMS Message
new QR_Sms('+1-555-...', 'Message')
Contact Card
new QR_VCard([...])
Network & Location QR Codes
QR codes for WiFi networks and geographical locations:
WiFi Network
new QR_WiFi('MyHomeWiFi', 'password', 'WPA')
Geographic Location
new QR_Text('geo:40.7128,-74.0060')
Usage Examples
Basic Generation
use QR_Code\Types\QR_Text;use QR_Code\Types\QR_Url;use QR_Code\Types\QR_EmailMessage; // Simple text QR code$textQR = new QR_Text('Hello, World!');$pngData = $textQR->png(); // Returns data URI // URL QR code with custom size$urlQR = new QR_Url('https://example.com');$urlQR->setSize(6); // Larger QR code$largePng = $urlQR->png(); // Email QR code$emailQR = new QR_EmailMessage( 'Hello from QR code!', // Message body 'QR Code Test' // Subject);$emailPng = $emailQR->png();
Advanced Configuration
use QR_Code\Types\QR_WiFi;use QR_Code\Types\QR_VCard; // WiFi QR code with all parameters$wifi = new QR_WiFi( 'NetworkName', // SSID 'password123', // Password 'WPA' // Security type (WEP/WPA/WPA2)); // Customize appearance$wifi->setSize(8) // Large size ->setMargin(2) // Smaller margin ->setErrorCorrectionLevel('H'); // High error correction $wifiPng = $wifi->png(); // vCard with full contact informationuse QR_Code\Types\vCard\Person;use QR_Code\Types\vCard\Phone; $person = new Person( 'John', // First name 'Doe', // Last name 'Mr.', // Title 'Example Corp', // Organization 'Software Engineer' // Job title); $phone = new Phone('+1-555-123-4567');$vcard = new QR_VCard($person, [$phone]); $vcardPng = $vcard->png();
Color & Style Variations
Customize QR code appearance with colors, sizes, and error correction levels:
Colorful QR Code Examples
Green Theme
Green colors
Blue Theme
Blue colors
Purple Theme
Purple colors
High Contrast
Yellow/Red
Large Colorful QR Code
Here's a large, vibrant QR code example:
🎨 Large Green QR Code
setSize(10)->setMargin(8)->setErrorCorrectionLevel('H')
->setBackColor(0xDCFCE7)->setForeColor(0x166534)
Output Format Comparison
Same QR Code, Different Formats
PNG (Default)
->png()
PNG (Large)
->setSize(8)->png()
PNG (Small)
->setSize(2)->png()
Performance Tips
- Cache QR codes: Generate once, reuse the data URI
- Choose appropriate sizes: Size 3-6 works well for most screens
- Error correction: Use 'L' for clean environments, 'H' for damaged surfaces
- Batch generation: Create multiple QR codes efficiently in loops
// Efficient batch processing$urls = ['https://example.com', 'https://test.com', 'https://demo.com'];$qrCodes = []; foreach ($urls as $url) { $qr = new QR_Url($url); $qr->setSize(4) ->setErrorCorrectionLevel('M'); // Medium error correction $qrCodes[] = $qr->png();} // Cache the results for reusecache()->put('qr_codes_batch', $qrCodes, now()->addHour());
Error Handling
try { $qr = new QR_Text('Your text here'); $qr->setSize(10) // Large size ->setMargin(6) // Big margin ->setErrorCorrectionLevel('H'); // High correction $qrCode = $qr->png(); // Verify the QR code was generated if (empty($qrCode)) { throw new \Exception('QR code generation failed'); } echo $qrCode; // Output data URI } catch (\Exception $e) { error_log('QR Code generation error: ' . $e->getMessage()); // Fallback or error handling}