-
-
Notifications
You must be signed in to change notification settings - Fork 302
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
[BUG] changing the viewbox size doesn't seem to expand the code to fit. #222
Comments
Hi. This is not a bug. The expectation that changing the
It's useful to change this attribute if you want to add additional content, e.g. text under the QR symbol. The setting php-qrcode/src/Output/QRMarkupSVG.php Lines 90 to 110 in 8c0da25
In order to change the size of the SVG to a fixed, which is what i assume you expect, you need to either add |
In fact, i should remove this option entirely before releasing v5. I added it a long time ago when i knew nothing about SVG and fell for the same misconception. It is misleading and most likely not widely used anyway. |
Well, while you were writing this out, I actually did go a similar path, only I overwrote the getViewBox() method so I wasn't overwriting other header info, and possibly no longer be compatible with your original header. protected function getViewBox(): string
{
$size = parent::getViewBox();
[$width, $height] = $this->getOutputDimensions();
$size = sprintf('0 0 %s %s', $width, $height);
return sprintf('%1$s" width="%2$s" height="%3$s',
$size,
($this->options->svgViewBoxSize ?? $width),
($this->options->svgViewBoxSize ?? $height)
);
} Would, instead of /**
* returns the <svg> header with the given options parsed
*
* @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg
*/
protected function header():string{
$width = null;
$height = null;
if ($this->options->scale) {
$width = sprintf(' width="%1$s"', $this->options->scale);
$height = sprintf(' height="%1$s"', $this->options->scale);
}
$header = sprintf(
'<svg xmlns="http://www.w3.org/2000/svg" class="qr-svg %1$s" viewBox="%2$s"%3$s%4$s preserveAspectRatio="%5$s">%6$s',
$this->options->cssClass,
$this->getViewBox(),
$width,
$height,
$this->options->svgPreserveAspectRatio,
$this->eol
);
if($this->options->svgAddXmlHeader){
$header = sprintf('<?xml version="1.0" encoding="UTF-8"?>%s%s', $this->eol, $header);
}
return $header;
} |
I was experimenting in the past but there's no "best" way to set the size for the SVG, so i decided to leave this to the user entirely. the |
Sigh, yeah. The whole point of the "S" in SVG. The issue I'm coming across, specific to me. I'm trying to import the QR codes, and the viewport is 0 0 41 41. which gimp makes a 41x41 pixel import. I can scale it up when importing, but it then becomes really fuzzy, like trying to upscale a jpg/png/etc. I was just trying to solve this from an import perspective. |
That sounds like the same issue i had when converting via ImageMagick - try the output from that example and see what happens. |
Ok, I just pulled/composer update and I'm running on dev-main. I copy-pasta'd your svg example here: and getting a viewport of 53 and it's trying to import as a 53x53 image:
|
I could be wrong, but it'd be nice to have the svg be large by default, for importing into things like gimp/photoshop/cad/non-html, browser. Then make them scale it down with css/html attributes. |
That is correct. I meant try the output from the imagick conversion example with the changed |
I'm going to close this issue here. Feel free to open a discussion for further questions. |
Like i said, that is not the main focus or use case for SVG output and the reason why i decided not to add these attributes. |
Oh, derp. I got: |
Gotcha, well at least you made it extendable, and you did a great job on the documentation, I personally appreciate that part! :-p |
Glad to hear because that's exactly why i'm doing this. |
Well I don't mind being your userland guinea pig. I'm using it over here, in case you're curious: https://qr.fr3nch.com |
I chose yours, because it's much more configurable, and it runs locally, verse google's graph api. I also wasn't going to pay bitly and other QR code hosters $35/month when I can make my own site. |
Ah yes the QR code scammers. Still a wild concept to me so generate a QR code and charge for it on a monthly basis - for tracking statistics you can get for free elsewhere. If i had the time and capacity i'd run such a website for free haha. Oh wait, i did (cheaply) |
Tested on 4.3, 5.0-beta, and main.
Describe the bug or unexpected behaviour
setting the
svgViewBoxSize
to an int, doesn't seem to fill the viewBox with the QrCode.Without setting the
svgViewBoxSize
, the output makes it<svg xmlns="http://www.w3.org/2000/svg" class="qr-svg qrcode" viewBox="0 0 41 41" preserveAspectRatio="xMidYMid">
.Setting it, and the only thing that changes is the
viewBox="0 0 500 500"
Unfortunately I don't know enough about SVG to know if this is the intended output change, or if there should be more.
Hopefully I'm just overlooking some setting that I should be using.
Steps to reproduce the behavior
Current code, simplified for testing.
Expected behavior
That if I set the viewBox size, that the QR code, (and svg logo inside) would expand to fill the view box.
Screenshots
SVG Gist
Environment (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: