Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function generate_qr_code($value)
- {
- $filename = $value.'.png';
- $fullpath = APPPATH.'../public/files/'.$filename;
- $logopath = APPPATH.'../assets/img/logo/kemdikbud.png';
- if (file_exists($fullpath)) {
- unlink($fullpath);
- }
- if (!file_exists($fullpath)) {
- $this->load->library('ciqrcode');
- $params['data'] = $value;
- $params['level'] = 'H';
- $params['size'] = 10;
- $params['savename'] = $fullpath;
- $this->ciqrcode->generate($params);
- $QR = imagecreatefrompng($fullpath);
- // memulai menggambar logo dalam file qrcode
- $logo = imagecreatefromstring(file_get_contents($logopath));
- imagecolortransparent($logo , imagecolorallocatealpha($logo , 0, 0, 0, 127));
- imagealphablending($logo , false);
- imagesavealpha($logo , true);
- $QR_width = imagesx($QR);//get logo width
- $QR_height = imagesy($QR);//get logo width
- $logo_width = imagesx($logo);
- $logo_height = imagesy($logo);
- // Scale logo to fit in the QR Code
- $logo_qr_width = $QR_width/2;
- $scale = $logo_width/$logo_qr_width;
- $logo_qr_height = $logo_height/$scale;
- imagecopyresampled($QR, $logo, $QR_width/4, $QR_height/3.5, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
- // Simpan kode QR lagi, dengan logo di atasnya
- imagepng($QR,$fullpath);
- }
- return $filename;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement