endroid / qr-code

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

[Feature Request] Implement logoPunchoutBackground in SVG writer #455

Open CodelineRed opened 1 month ago

CodelineRed commented 1 month ago

logoPunchoutBackground(true) has no effect on SVG files.

Screenshot 2024-10-09 105946

<?php
use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\Writer\SvgWriter;

foreach (['png', 'svg'] as $extension) {
    $generalBuilder = Builder::create();

    if ($extension === 'png') {
        $generalBuilder->writer(new PngWriter());
    } else {
        $generalBuilder->writer(new SvgWriter());
    }

    $generalBuilder->writerOptions([])
        ->data('https://github.com/Bacon/BaconQrCode')
        ->encoding(new Encoding('UTF-8'))
        ->size(320)
        ->margin(10)
        ->logoPath('logo.png')
        ->logoResizeToWidth(100)
        ->logoPunchoutBackground(true);
    }

    $generalBuilder->build()->saveToFile('qrcode.' . $extension);
}

Tested with 5.1.0

DharmenderRajput commented 1 week ago

Confirmed with v6.0.0