-
-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
I was not able to make a pull request. This library works fine, only I was not able to retrieve the image as a base64 string, so I made some modifications. For anyone needing this.
$img= QRcode::png('PHP QR Code :)','*');
If you use '*' as the filename the function will return a base64 string that you can use in your application:
$r='<img width="500" src="data:image/png;base64,'.$img.'"/>';
Required changes are in qrimage
//----------------------------------------------------------------------
public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE)
{
$image = self::image($frame, $pixelPerPoint, $outerFrame);
$r='';
if ($filename === false) {
Header("Content-type: image/png");
ImagePng($image);
} else {
if($saveandprint===TRUE){
ImagePng($image, $filename);
header("Content-type: image/png");
ImagePng($image);
}else{
if($filename=='*') {
ob_start();
ImagePng($image);
$r = base64_encode(ob_get_contents());
ob_end_clean();
} else {
ImagePng($image, $filename);
}
}
}
ImageDestroy($image);
return $r;
}
in qrencode
//----------------------------------------------------------------------
public function encodePNG($intext, $outfile = false,$saveandprint=false)
{
try {
ob_start();
$tab = $this->encode($intext);
$err = ob_get_contents();
ob_end_clean();
if ($err != '')
QRtools::log($outfile, $err);
$maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
return QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint);
} catch (Exception $e) {
QRtools::log($outfile, $e->getMessage());
}
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels