KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Extract image from QRCode? #1903

Closed Keith Burke opened this topic on on Feb 12, 2021 - 2 comments

Keith Burke commented on Feb 12, 2021

So, I have Koolreports 5 integrated with CodeIgniter4 and all works fine. However, I want to use tiny pieces of KoolReports in my CI views without the KoolReport View. For example, I want to use a QR Barcode in a piece of javascript that puts locations on a OpenStreetMaps map. I just want the image, not the surrounding KR formatting and javescript.

So I have something like this [Assume controller includes the KR Autoload perfectly] ...

                    $qrCode = \koolreport\barcode\QRCode::html(array(
                                "format" => "png",
                                "value" => "geo:53.1126812,-6.260661",
                                "size" => 150,
                                "foregroundColor" => array(0, 0, 0),
                                "backgroundColor" => array(255, 255, 255),
                              ));
                    echo $qrReport;

It outputs something like this...

    <script type='text/javascript' src='/koolreport_assets/3409401219/KoolReport.js'></script>
    <krwidget widget-name='' widget-type='koolreport/barcode/QRCode'>
        <img src='data:image/PNG;base64,iVBORw0KGgoAA   <** SNIP**>  VORK5CYII='>
    </krwidget>

Where as I just want the actual image with nothing else. A little like this ...

<img src='data:image/PNG;base64,iVBORw0KGgoAA   <** SNIP**>  VORK5CYII='>

I got around it by amending the above code to this...

            preg_match_all('/<img[^>]+>/i',$qrCode, $image_matches);            
            echo implode($image_matches[0]);

So, my workaround works for me. I'm just wondering if there is a nicer option. Maybe a flag to QRCode to output just the image?

David Winterburn commented on Feb 15, 2021

Hi Keith,

Overall I think your solution is indeed the shortest one. One other is to override the render() method of the QRCode widget, which I don't think is very convenient. Let us know if you need further help. Thanks!

Keith Burke commented on Feb 15, 2021

Thanks David. I'll stick with my solution.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

BarCode