Advertisement
juliarnasution

fungsi generate qrcode

Mar 28th, 2020
2,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 KB | None | 0 0
  1. public function generate_qr_code($value)
  2.     {  
  3.         $filename = $value.'.png';
  4.         $fullpath = APPPATH.'../public/files/'.$filename;
  5.         $logopath = APPPATH.'../assets/img/logo/kemdikbud.png';
  6.         if (file_exists($fullpath)) {
  7.             unlink($fullpath);
  8.         }
  9.        
  10.         if (!file_exists($fullpath)) {
  11.             $this->load->library('ciqrcode');
  12.             $params['data'] = $value;
  13.             $params['level'] = 'H';
  14.             $params['size'] = 10;
  15.             $params['savename'] = $fullpath;
  16.             $this->ciqrcode->generate($params);
  17.             $QR = imagecreatefrompng($fullpath);
  18.              // memulai menggambar logo dalam file qrcode
  19.              $logo = imagecreatefromstring(file_get_contents($logopath));
  20.              imagecolortransparent($logo , imagecolorallocatealpha($logo , 0, 0, 0, 127));
  21.  
  22.              imagealphablending($logo , false);
  23.              imagesavealpha($logo , true);
  24.  
  25.              $QR_width = imagesx($QR);//get logo width
  26.              $QR_height = imagesy($QR);//get logo width
  27.  
  28.              $logo_width = imagesx($logo);
  29.              $logo_height = imagesy($logo);
  30.              
  31.             // Scale logo to fit in the QR Code
  32.              $logo_qr_width = $QR_width/2;
  33.              $scale = $logo_width/$logo_qr_width;
  34.              $logo_qr_height = $logo_height/$scale;
  35.  
  36.              imagecopyresampled($QR, $logo, $QR_width/4, $QR_height/3.5, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
  37.              // Simpan kode QR lagi, dengan logo di atasnya
  38.              imagepng($QR,$fullpath);
  39.         }
  40.          return $filename;
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement