2
29

Get a QR

Generating 1 QRmii by program costs 1 credit. To buy credit units, click on the cart Credit 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=
loginYour identification code.
passwordYour password.
urlThe complete URL to redirect.
fgForeground color of the QR.
bgBackground color of the QR.
qualityQuality level of the QR.
sizeSize 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:

L7%25px
M15%25px
Q25%29px
H33%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:

  1. require_once 'sendhttp.php';

Loads the code of the sendget function provided by iZend.

  1. define('ROOT_DIR', dirname(__FILE__));
  2. define('QRMII_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'qrmii');

Defines the directory where the PNG of a QR code is saved.

  1. 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.

  1.     $curl = 'http://qrmii.com/api/getqr';
  2.     $args = array(
  3.         'login'     => $login,
  4.         'password'  => $password,
  5.         'url'       => $url,
  6.         'fg'        => $fg,
  7.         'bg'        => $bg,
  8.         'quality'   => $quality,
  9.         'size'      => $size,
  10.     );

Sets $curl to the URL of the getqr action. Fills the array $args with the parameters of the getqr action.

  1.     $response=sendget($curl, $args);

Sends the HTTP request with sendget.

  1.     if (!$response or $response[0] != 200) {
  2.         return false;
  3.     }

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.

  1.     $r = $response[1]['Content-Disposition'];
  2.     $filename=substr($r, strpos($r, 'filename=')+9);
  3.     $hash=basename($filename, '.png');

Extracts the short URL from the file name given in the header of the response.

  1.     $data=$response[2];
  2.  
  3.     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.

  1.     return $hash;
  2. }

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
SEE ALSO

Manage your account and Check your credit

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].