Endroid\QrCode\QrCode::render PHP Method

render() public method

Render the QR Code then save it to given file name or output it to the browser when file name omitted.
public render ( null | string $filename = null, null | string $format = 'png' ) : QrCode
$filename null | string File name of the QR Code
$format null | string Format of the file (png, jpeg, jpg, gif, wbmp)
return QrCode
    public function render($filename = null, $format = 'png')
    {
        $this->create();
        if ($format == 'jpg') {
            $format = 'jpeg';
        }
        if (!in_array($format, $this->image_types_available)) {
            $format = $this->image_type;
        }
        if (!function_exists('image' . $format)) {
            throw new ImageFunctionUnknownException('QRCode: function image' . $format . ' does not exists.');
        }
        if ($filename === null) {
            $success = call_user_func('image' . $format, $this->image);
        } else {
            $success = call_user_func_array('image' . $format, array($this->image, $filename));
        }
        if ($success === false) {
            throw new ImageFunctionFailedException('QRCode: function image' . $format . ' failed.');
        }
        return $this;
    }

Usage Example

Beispiel #1
0
 public static function createQRCode($file_path)
 {
     // get server info
     $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0;
     $hostname = $_SERVER['SERVER_NAME'];
     $port = $_SERVER['SERVER_PORT'];
     // Create folder
     $date = date('Ymd');
     $upload_path = '/upload/qrcode/' . $date . '/';
     $dir = public_path() . $upload_path;
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     // QR Code
     $qrCode = new QrCode();
     $qrCode->setText($protocol . $hostname . ':' . $port . $file_path);
     $image = $qrCode->get();
     $fileName = md5(date('YmdHis')) . '.png';
     // Save QR code to image
     $qrCode->render($dir . $fileName);
     //
     return $upload_path . $fileName;
 }
All Usage Examples Of Endroid\QrCode\QrCode::render