PHP code example of remymazmanian / qr-studio
1. Go to this page and download the library: Download remymazmanian/qr-studio library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
remymazmanian / qr-studio example snippets
use QrStudio\DesignOptions;
use QrStudio\QrRenderer;
$renderer = new QrRenderer();
// Simplest case.
file_put_contents('qr.svg', $renderer->result('https://example.com', 'svg')->getString());
// Styled.
$options = DesignOptions::fromArray([
'module_style' => DesignOptions::MODULE_DOTS,
'eye_style' => DesignOptions::EYE_CIRCLE,
'frame_style' => DesignOptions::FRAME_ROUNDED_CARD,
'foreground_color' => '#1f3d7a',
'eye_color' => '#c2410c',
'label_text' => 'Scan me',
'qr_size' => 720,
]);
file_put_contents('styled.png', $renderer->result('https://example.com', 'png', $options)->getString());
$values = array_replace(
DesignOptions::defaults(),
DesignOptions::presets()['circle']['values'],
);
$options = DesignOptions::fromArray($values);
use QrStudio\PayloadFactory;
$factory = new PayloadFactory();
$factory->make(['type' => 'url', 'website_url' => 'https://example.com']);
$factory->make(['type' => 'text', 'plain_text' => 'Hello']);
$factory->make(['type' => 'phone', 'phone_number' => '+1 555 010 0100']);
$factory->make(['type' => 'email', 'email_address' => '[email protected] ', 'email_subject' => 'Hi']);
$factory->make(['type' => 'wifi', 'wifi_ssid' => 'Guest', 'wifi_password' => 'pw', 'wifi_encryption' => 'WPA']);
$factory->make(['type' => 'vcard', 'vcard_name' => 'Ada Lovelace', 'vcard_email' => '[email protected] ']);
use QrStudio\ColorContrast;
if (ColorContrast::contrastRatio('#888888', '#ffffff') < 3.0) {
// too low - reject it
}
$result = $renderer->result($payload, 'svg', $options);
$result->getString(); // raw SVG or PNG bytes
$result->getDataUri(); // data: URI, handy for inline <img>
$result->getMimeType();
$result->saveToFile('/path/to/qr.svg');
$renderer->dataUri($payload); // shorthand