endroid / qr-code

QR Code Generator
https://endroid.nl
MIT License
4.33k stars 721 forks source link

Could it be that the readme is outdated? #441

Closed gilberto-009199 closed 4 months ago

gilberto-009199 commented 4 months ago

Hello, I found your library and thought it would be cool to test it out, but it's not working for me. I'm getting an error:

[Wed Feb 28 18:37:03 2024] PHP Fatal error:  Uncaught Error: Class 'Endroid\QrCode\ErrorCorrectionLevel' not found in /home/administrador/Desktop/Propheta/propheta.net/sales/qrcode.php:19
Stack trace:
#0 {main}
  thrown in /home/administrador/Desktop/Propheta/propheta.net/sales/qrcode.php on line 19
[Wed Feb 28 18:37:03 2024] [::1]:34186 [500]: GET /qrcode.php - Uncaught Error: Class 'Endroid\QrCode\ErrorCorrectionLevel' not found in /home/administrador/Desktop/Propheta/propheta.net/sales/qrcode.php:19

I'm working with version "endroid/qr-code": "^4.6". I tried using one of your examples, but it didn't work. Here's my code: index.php

<?php
require_once __DIR__ . '/vendor/autoload.php';

use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\Label\Label;
use Endroid\QrCode\Logo\Logo;
use Endroid\QrCode\RoundBlockSizeMode;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\Writer\ValidationException;

$writer = new PngWriter();

// Create QR code
$qrCode = QrCode::create('Life is too short to be generating QR codes')
    ->setEncoding(new Encoding('UTF-8'))
    ->setErrorCorrectionLevel(ErrorCorrectionLevel::Low)
    ->setSize(300)
    ->setMargin(10)
    ->setRoundBlockSizeMode(RoundBlockSizeMode::Margin)
    ->setForegroundColor(new Color(0, 0, 0))
    ->setBackgroundColor(new Color(255, 255, 255));

$result = $writer->write($qrCode);

// Validate the result
$writer->validateResult($result, 'Life is too short to be generating QR codes');

The only thing I modified was removing the logo. Could it be that the readme is outdated? Is there something missing in my code or project?

image error

image dir vendor

endroid commented 4 months ago

Hi @gilberto-009199 looks like you used an example from the 5.x readme while running a 4.x version. Make sure you are looking at the readme for your version if you run an older version. For instance if you installed 4.8.5 look at https://github.com/endroid/qr-code/tree/4.8.5. Good luck!

gilberto-009199 commented 4 months ago

Thanks!