Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpqrcode changing qr code color

Tags:

php

qr-code

I am trying to generate a different colored QR Code using phpqrcode library.

My code sample is below:

<?php
    include('./phpqrcode/qrlib.php');
    $uri=$_GET['uri'];
    $backColor = 0xFFFFFF;
    $foreColor = 0x000066;
    header("Content-Type: image/png");
    QRcode::png($uri, false, QR_ECLEVEL_L, 6, 1, false, $backColor, $foreColor);
?>

However, the colors just seem to get ignored and the QR code always comes out as black on white.

I am pretty sure I am using the latest version of the library (v1.1.4):

http://sourceforge.net/projects/phpqrcode/files/releases/

Anyone managed to get this working?

like image 742
CPP Avatar asked May 06 '26 20:05

CPP


1 Answers

The sourceforge version of the method looks like the following:

static QRcode::png  (
    $text,
    $outfile = false,
    $level = QR_ECLEVEL_L,
    $size = 3,
    $margin = 4,
    $saveandprint = false 
)   

and does not include any colours. You seem to be looking for the GitHub version instead, that defines the method as the following:

public static function png(
    $text, 
    $outfile = false, 
    $level = QR_ECLEVEL_L, 
    $size = 3, 
    $margin = 4, 
    $saveandprint=false, 
    $back_color = 0xFFFFFF, 
    $fore_color = 0x000000
) {

(Psst, the article you read also mentions it: "Start by downloading the latest PHP QR Code library from GitHub", and it also includes a link to the GitHub project)

like image 83
h2ooooooo Avatar answered May 09 '26 11:05

h2ooooooo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!