Get a QR
Generating 1 QRmii by program costs 1 credit. To buy credit units, click on the cart in the banner of your home page.
Download the code of the sendget
function defined in the file sendhttp.php.
Copy the file in the space of your application.
NOTE: See the page Call the service in PHP for a description of the sendget
function.
URL
https://qrmii.com/api/getqr?login=&password=&url=&fg=&bg=&quality=&size=
login | Your identification code. |
---|---|
password | Your password. |
url | The complete URL to redirect. |
fg | Foreground color of the QR. |
bg | Background color of the QR. |
quality | Quality level of the QR. |
size | Size of the QR. |
url
is a string with the standard format scheme://domain:port/path?query#fragment
.
The part scheme://domain
is mandatory. scheme
is generally set to http
.
NOTE: url
will be normalized by the program so that different expressions which actually represent the same URL return the same short URL.
fg
and bg
have the standard format RRGGBB in hexadecimal with or without a # (HASHMARK).
quality
defines the error percentage of the reproduction of the QR.
The higher the correction rate is, the bigger is the minimum size of the QR:
L | 7% | 25px |
M | 15% | 25px |
Q | 25% | 29px |
H | 33% | 33px |
size
multiplies the minimum size of the QR by a value between 1 and 15.
EXAMPLE: A QRmii of quality M and of size 4 will be 100 pixels by 100 pixels.
IMPORTANT: QR code readers work better if the contrast between the color of the QR and its background is strong. Generate some samples from the public home page and check that the QR codes are readable with a smartphone.
Add the file getqr.php with the following content:
- require_once 'sendhttp.php';
Loads the code of the sendget
function provided by iZend.
- define('ROOT_DIR', dirname(__FILE__));
- define('QRMII_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'qrmii');
Defines the directory where the PNG of a QR code is saved.
- function getqr($login, $password, $url, $fg='#000000', $bg='#ffffff', $quality='M', $size='2') {
Defines the function getqr
.
$login
is your identification code. $password
is your password.
$url
contains the complete URL which will be redirected by the QRmii.
$fg
gives the color of the QR, black by default.
$bg
gives the background color of the QR, white by default.
$quality
gives the quality level of the QR, M by default.
$size
gives the size of the QR, 2 by default.
- $curl = 'http://qrmii.com/api/getqr';
- $args = array(
- 'login' => $login,
- 'password' => $password,
- 'url' => $url,
- 'fg' => $fg,
- 'bg' => $bg,
- 'quality' => $quality,
- 'size' => $size,
- );
Sets $curl
to the URL of the getqr action.
Fills the array $args
with the parameters of the getqr action.
- $response=sendget($curl, $args);
Sends the HTTP request with sendget
.
- if (!$response or $response[0] != 200) {
- return false;
- }
If $response
is false
, the server is unreachable.
If $response[0]
doesn't contain the HTTP return code 200 Ok, an execution error has occurred.
In case of error, getqr
returns false.
- $r = $response[1]['Content-Disposition'];
- $filename=substr($r, strpos($r, 'filename=')+9);
- $hash=basename($filename, '.png');
Extracts the short URL from the file name given in the header of the response.
- $data=$response[2];
- file_put_contents(QRMII_DIR . DIRECTORY_SEPARATOR . $filename, $data);
Writes the body of the response, the binary representation of the PNG image of the QR code, in the folder defined by the constant QRMII_DIR.
- return $hash;
- }
Returns the short URL.
EXAMPLE
Assuming you have saved the files sendhttp.php and getqr.php in the current directory, create the subdirectory qrmii, run PHP in interactive mode, load the getqr
function and call it with your identification code, your password and a URL in argument:
$ mkdir qrmii
$ php -a
php > require_once 'getqr.php';
php > echo getqr('abcdef', 'ABCDEF', 'https://www.qrmii.com');
a944d525
The image of the QR is in the file qrmii/a944d525.png.
Try a color and a larger size:
php > echo getqr('abcdef', 'ABCDEF', 'https://www.qrmii.com', '#ff9900', '#000000', 'L', 8);
a944d525
php > quit
Comments