Skip to content

Modifications #1

@aducom

Description

@aducom

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());
        
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions