Code Monkey home page Code Monkey logo

Comments (8)

endroid avatar endroid commented on August 20, 2024

I agree, this would be a useful feature. Hope anyone is willing to contribute on this.

from qr-code.

lahdekorpi avatar lahdekorpi commented on August 20, 2024

I'm guessing this ain't happening?

from qr-code.

endroid avatar endroid commented on August 20, 2024

Not unless someone is willing to contribute on this feature.

from qr-code.

endroid avatar endroid commented on August 20, 2024

Looks like the new core library used in 2.x supports this feature. Please try it and let me know if this works for you. Please note that documentation of 2.x is not yet up to date and some features like adding a logo or a label still need to be ported to this new version.

from qr-code.

Emilio-Staropoli avatar Emilio-Staropoli commented on August 20, 2024

Doesn't work for me, I'm trying
writeString(SvgWriter::class)
but I always get a png image. Tried playing around a bit (with MIME type etc) but to no avail: I get an encoding error when using image/svg+xml
Please help :(

from qr-code.

simondowdles avatar simondowdles commented on August 20, 2024

@Emilio-Staropoli

The SVG works perfectly. Here is how I used it:

$qrCode = new QrCode( get_site_url() . '/some/path/to/api/' );
            $qrCode
                ->setMargin(10)
                ->setEncoding('UTF-8')
                ->setErrorCorrectionLevel( ErrorCorrectionLevel::HIGH )
                ->setBackgroundColor( [ 'r' => 255, 'g' => 255, 'b' => 255 ] )
                ->setForegroundColor( [ 'r' => 0, 'g' => 0, 'b' => 0 ] )
                ->setLabel( 'Test', 12, SD_PATH . 'vendor/endroid/qrcode/assets/noto_sans.otf', LabelAlignment::CENTER, [ 'b' => 20 ] )
                ->setLogoPath( SD_PATH . 'assets/img/eye.png')
                ->setLogoWidth( 150 )
                ->setSize(200)
                ->setWriterByName('png');
            
            $svg = new SvgWriter();
            
            echo $svg->writeString( $qrCode ) ;

It's important that you pass your original QrCode class instance back to SvgWriter, and in my case this was $qrCode instance above.

Of course there will be things like logos that won't work as you can't convert bitmap to vector, but for a quick SVG solution it works perfectly fine! I also do not see any code that allows for the label to be rendered using SVG.

The SVG also displays fine when just echo / printing it out, whereas the PNG needed to be base64_encoded as a data URI.

from qr-code.

endroid avatar endroid commented on August 20, 2024

@Emilio-Staropoli you should use the setWriter() method to set your writer or instantiate the SvgWrtier yourself and use its writeString method.

from qr-code.

coffeduong avatar coffeduong commented on August 20, 2024

1 more thing, set header header('Content-Type: '.$svg->getContentType()); to help browser understand it's SVG image

from qr-code.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.