Basic usage

The following example outputs a PNG image at the default size, medium error correction.

  <?php
    require_once("Image/QRCode.php");
    
    $qr = new Image_QRCode();
    $qr->makeCode("Hello, world");
  ?>

Changing the output image type

This example will output a JPEG file instead of a PNG.

  <?php
    require_once("Image/QRCode.php");
    
    $qr = new Image_QRCode();
    
    $options = array(
      "image_type" => "jpeg"
    );
    $qr->makeCode("Hello, world", $options);
  ?>

Returning an object instead of outputting

If you need the GD object returned instead of outputting direct to the browser, use the following example.

  <?php
    require_once("Image/QRCode.php");
    
    $qr = new Image_QRCode();
    
    $options = array(
      "output_type" => "return"
    );
    $gd_object = $qr->makeCode("Hello, world", $options);
  ?>

Altering the error correction level

Image_QRCode supports 4 error correction levels:

The default is "M".

  <?php
    require_once("Image/QRCode.php");
    
    $qr = new Image_QRCode();
    
    $options = array(
      "error_correct" => "H"
    );
    $qr->makeCode("Hello, world", $options);
  ?>

Changing the module (image) size

The size of the generated QR image can be adjusted as follows. This does not affect error correction or similar.

  <?php
    require_once("Image/QRCode.php");
    
    $qr = new Image_QRCode();
    
    $options = array(
      "module_size" => 30 
    );
    $qr->makeCode("Hello, world", $options);
  ?>

Changing the code version

The version of the QR code can be altered by passing options to the constructor. Note that in most cases this will result in an increase in image size.

  <?php
    require_once("Image/QRCode.php");

	$options = array(
	  "version" => 5
	);    
    $qr = new Image_QRCode($options);
    
    $qr->makeCode("Hello, world");
  ?>