Bacon / BaconQrCode

QR Code Generator for PHP
BSD 2-Clause "Simplified" License
1.82k stars 208 forks source link

How to use transparent background? #139

Closed jagermeister34 closed 5 months ago

jagermeister34 commented 1 year ago

Hello, I am generating a QR code using this library and registering this QR code in a folder. The background of this QR code is constantly white and I have to open it manually later using software such as CorelDraw - Illustrator and delete it. Is there a way to automatically produce this without a white background, ie transparent?

My codes;

    use BaconQrCode\Renderer\Image\Svg;
    use BaconQrCode\Writer;
    use BaconQrCode\Renderer\Color\Cmyk;

    function utf8Encode($string) {
        return iconv(mb_detect_encoding($string, mb_detect_order(), true), 'UTF-8', $string);
    }

    $qrCodeContent = utf8Encode("BEGIN:VCARD\nVERSION:3.0\nN:". $name ." ". $surname ."\nEMAIL:$email\nTEL;TYPE=CELL:$gsmno\nTEL;TYPE=WORK:$is_telefonu\nURL:$website\nADR:". $ofisadres ."\nEND:VCARD");

    $renderer = new Svg();
    $renderer->setForegroundColor(new Cmyk(0, 0, 0, 100));

    $writer = new Writer($renderer);
    $qrCodeSvg = $writer->writeString($qrCodeContent);

    $filename = ''. $username .'.svg';

    $path = 'qr/' . $filename;

    file_put_contents($path, $qrCodeSvg);