Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG output #24

Closed
hyjk2000 opened this issue Feb 9, 2015 · 8 comments
Closed

SVG output #24

hyjk2000 opened this issue Feb 9, 2015 · 8 comments

Comments

@hyjk2000
Copy link

hyjk2000 commented Feb 9, 2015

Vector formats are useful for QR Codes. Given the popularity and browser support of SVG, I think many people would like to have SVG output in this project.

@endroid
Copy link
Owner

endroid commented Feb 10, 2015

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

@endroid endroid assigned endroid and unassigned endroid Feb 28, 2015
@endroid endroid changed the title Feature Request: SVG output Feature request: SVG output Jun 21, 2016
@endroid endroid changed the title Feature request: SVG output SVG output Jan 22, 2017
@lahdekorpi
Copy link

I'm guessing this ain't happening?

@endroid
Copy link
Owner

endroid commented Feb 5, 2017

Not unless someone is willing to contribute on this feature.

@endroid endroid removed the contribute label Apr 8, 2017
@endroid
Copy link
Owner

endroid commented Apr 8, 2017

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.

@endroid endroid closed this as completed Apr 8, 2017
@Emilio-Staropoli
Copy link

Emilio-Staropoli commented Jul 10, 2017

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 :(

@simondowdles
Copy link

simondowdles commented Jul 21, 2017

@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.

@endroid
Copy link
Owner

endroid commented Jul 22, 2017

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

@coffeduong
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants