-
It return the image black and white and not with colors as shown in examples
|
Beta Was this translation helpful? Give feedback.
Replies: 23 comments 4 replies
-
You're invoking the output interface with a different set of options - you should use the same options instance for both invocations, that's how it's done internally. $options = new QRCodeLogoOptions;
// ... set ALL options on this instance
// invoke
$qrOutputInterface = new QRCodeLogo($options, (new QRCode($options))->getMatrix($data)); Also, you can simplify the whole thing by using $options = new QRCodeLogoOptions;
// ...
$options->outputType = QRCode::OUTPUT_CUSTOM;
$options->outputInterface = QRCodeLogo::class;
(new QRCode($options))->render($data, FCPATH.'/image.png'); |
Beta Was this translation helpful? Give feedback.
-
Thanks, i found what i was doing wrong. In fact there is two problems here, why same options can send twice to qrcode library instead of once The second one is if I use different options this And another problem that i am trying to figure out is how can i make an SVG with my logo xD. |
Beta Was this translation helpful? Give feedback.
-
Also the outputType does not work because the Logo extends from QRImage class :( |
Beta Was this translation helpful? Give feedback.
-
There's absolutely no reason to invoke more than one options instance for the same qrcode/output instance like in your code above - that example is even using different version numbers - it cannot work properly. |
Beta Was this translation helpful? Give feedback.
-
But i have the svg file for the logo, i am wondering if i am stupid enough not to know how to generate a qrcode svg with my svg logo file. I just want to know if this is possible with this current version of your library or i might need to go somewhere else ? |
Beta Was this translation helpful? Give feedback.
-
It surely is possible. This is probably what you're looking for. In order to do that, you'd just need to add your code in the (extended) |
Beta Was this translation helpful? Give feedback.
-
It is possible to have a demo for this ? :D i give you a lot of thanks if you can have a demo |
Beta Was this translation helpful? Give feedback.
-
Following the first SO answer, you'd need to add the following: <image x="10" y="20" width="80" height="80" href="recursion.svg" /> which in PHP basically translates to: $svg .= '<image x="'.$logoX.'" y="'.$logoY.'" width="'.$logoWidth.'" height="'.$logoHeight.'"
href="data:image/svg+xml;base64,'.base64_encode($svgLogo).'" />'; |
Beta Was this translation helpful? Give feedback.
-
Ok so it worked i have what i want but there is one problem
for the first two variables $lw and $lh i don't know how to calculate exactly the position. Do you know how to get those dimensions ? because if i change now the size of the logo overlaps the qrcode and i need to readjust these vars |
Beta Was this translation helpful? Give feedback.
-
I can upload an example for what i did if i somehow calculate those vars |
Beta Was this translation helpful? Give feedback.
-
I think all you need to know is in this example. This is how you calculate the matrix size of the QR Code (+2 * quiet zone size, 4 modules by default), multiplied by |
Beta Was this translation helpful? Give feedback.
-
No dude the SVG MARKUP doesnt care about the scale, in fact that option for the svg does not work
AND inside the Logo class
|
Beta Was this translation helpful? Give feedback.
-
First, don't "DUDE" me, second, why do you want me to do your job?`We're talking about basic algebra here. |
Beta Was this translation helpful? Give feedback.
-
Ok i'm sorry, and yes basic algebra but for the svg, i just wanted to make the library better, for the most part i will never change the logo so for me the job is done. The basic algebra does not apply if you put the svg logo inside the generated svg. the width of the logo is the same as in the options because it is an svg file that scales automatically The only problem is where to put the logo, anyway i will check this later. Thanks for the help i really appreciate it if you wouldn't say is possible to make svg with logo i would never tried. |
Beta Was this translation helpful? Give feedback.
-
Look, i'm not an expert in SVG and it requires for me the same effort to google (in my free time) as it would for you. I can help you with internals of this library - that is all. If SVG wasn't this messy, i had already implemented a proper solution to add logos for it - unlike GD and Imagick, there's no proper "one fits all" soultion. This, and the reason that logos are usually only a commercial feature are reasons why i didn't. |
Beta Was this translation helpful? Give feedback.
-
Yes i understand you, but i am telling you i had the job 90% done. The only problem is these vars
I believe these vars must be exactly how you space out the logo when you create the matrix with the empty space for the logo I don't know how can i get these vars from your library This function :
|
Beta Was this translation helpful? Give feedback.
-
As i see inside that function somewhere down the line you asign
These vars, these are exactly what i need. Now i'm starting to understand it better :D |
Beta Was this translation helpful? Give feedback.
-
As i mentioned before, since there's not "the one" solution for SVG, i don't want to add it yet. You can instead post your solution here and i'll move this issue to discussions under Q&A. |
Beta Was this translation helpful? Give feedback.
-
So i have done it if you want to push it for the SVG example with Logo this is it man :D sorry for bothering and thanks class QRCodeLogo extends QRMarkup{
/**
* @param string|null $file
* @param string|null $logo
*
* @return string
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
*/
public function dump(string $file = null, string $logo = null):string{
$this->options->returnResource = true;
if(!is_file($logo) || !is_readable($logo)){
throw new QRCodeOutputException('invalid logo');
}
$this->matrix->setLogoSpace(
$this->options->logoSpaceWidth,
$this->options->logoSpaceHeight
// not utilizing the position here
);
$width = $this->options->logoSpaceWidth;
$height = $this->options->logoSpaceHeight;
if(($width % 2) === 0){
$width++;
}
if(($height % 2) === 0){
$height++;
}
$length = $this->options->version * 4 + 17;
$qz = ($this->moduleCount - $length) / 2;
$startX = (($length - $width) / 2) + $qz + 0.5;
$startY = (($length - $height) / 2) + $qz + 0.5;
// there's no need to save the result of dump() into $this->image here
$this->image = parent::dump($file);
$ql = $this->matrix->size();
$data = file_get_contents($logo);
$logo_svg = '<image x="'.$startX.'" y="'.$startY.'" width="'.$this->options->logoSpaceWidth.'" height="'.$this->options->logoSpaceHeight.'" href="data:image/svg+xml;base64,'.base64_encode($data).'" />';
$this->image = str_replace('</svg>', $logo_svg.'</svg>', $this->image);
// scale the logo and copy it over. done!
// imagecopyresampled($this->image, $im, ($ql - $lw) / 2, ($ql - $lh) / 2, 0, 0, $lw, $lh, $w, $h);
$imageData = $this->image;
if($file !== null){
$this->saveToFile($imageData, $file);
}
if($this->options->imageBase64){
$imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData);
}
return $imageData;
}
} |
Beta Was this translation helpful? Give feedback.
-
Just one thing: since the markup class handles more than just SVG, i'd rather overwrite the |
Beta Was this translation helpful? Give feedback.
-
Hi @crustamet I have tried your solution with Copy&Paste but it didn't work with me, any suggestions? The Options:
|
Beta Was this translation helpful? Give feedback.
-
The QRCode Option class must be extended from a SVG lib or someth !important : the SVG to logo png must be implemented first, i had some experience with SVG a long time ago so i made this work like this Im posting here my working implementation
|
Beta Was this translation helpful? Give feedback.
-
if that does not help you i can talk with you on discord crustamet#1308 |
Beta Was this translation helpful? Give feedback.
So i have done it if you want to push it for the SVG example with Logo this is it man :D sorry for bothering and thanks
The library is good