Vishwajeet Kumar
Vishwajeet Kumar

Reputation: 33

How to insert image along with text in QR Code generator

Insert an image along with text in QR Code generator.So after scanning (text and image) both should appear on screen.

I am using CIqrcode library of php(codeigniter). For inserting text it is fine but for image that path is displaying on screen.

I have used file_get_contents($path) and storing it into $params['data'] and passing $params as parameter

$this->ciqrcode->generate($params,..,...,).

but only path is displaying on screen.

Any idea about this??

Upvotes: 2

Views: 2983

Answers (2)

Alex Mac
Alex Mac

Reputation: 2993

Please use below mentioned code for the same. Also make sure you have given enough permissions to your /assets/qrcode/ folder.

$image = FCPATH . 'assets/qrcode/' . $id . '.png';
if (!file_exists($image)):
    $this->load->library('ciqrcode');
    $config['cacheable'] = true; //boolean, the default is true
    $config['quality'] = true; //boolean, the default is true
    $config['black'] = array(0, 89, 170); // array, default is array(255,255,255)
    $config['white'] = array(0, 89, 170); // array, default is array(0,0,0)
    $this->ciqrcode->initialize($config);

    $params['white'] = array(0, 89, 170); // array, default is array(255,255,255)
    $params['size'] = 100; //interger, the default is 1024
    $params['savename'] = $image;
    $params['data'] = '<img src="https://i.sstatic.net/ZfPaO.jpg" />';
    $params['level'] = 'H';
    $this->ciqrcode->generate($params);
endif;

Upvotes: 1

Vishwajeet Kumar
Vishwajeet Kumar

Reputation: 33

$filePath = null;
        if(LB_DESIGN) {
            $filePath = $this->filepath_model->getPathFolder_User($user_id);
        }else{
            $filePath = DE_PATH.'/web/test/file_system/user/'.$user_id;
        }
        $path = glob ($filePath."/photo.*");
        $img_src = null;
        if(count($path)){
             $file = basename($path[0]);
             $img_src = $filePath.'/'.$file;
         }else{
             $img_src = DE_PATH."/img/upload_logo.jpg";
         }
        $params['data'] = "Student Name: ".$row['certificate_name']."\nEmail ID: ".$emailId."\nAdmission No: ".$row['admission_no']."\nCourse Name: ".$row['course_name']."\nGrade: ".$grade."\nDate of Completion: ".$dateOfComplete."\nNOS/QPCode: ".$skill_code;
        $params['level'] = 'L';
        $params['size'] = 10;
        $data['myPath'] = $this->load->view('student_final_certificate');
        $params['savename'] = $data['myPath']."qrcode.png";
        $this->ciqrcode->generate($params);
    }
        return $data;   
  }//get html content

Upvotes: 1

Related Questions