Commit 444e9510 by Tobin

dc

parent 2f39e1d8
......@@ -109,8 +109,8 @@
$QR = imagecreatefrompng('https://chart.googleapis.com/chart?cht=qr&chld=H|1&chs=500x500&chl='.$qr_id);
$logo = imagecreatefromstring(file_get_contents($logo));
$qrWidth = imagesx($QR)/3;
$qrHeight = imagesy($QR)/3;
$qrWidth = imagesx($QR)/2;
$qrHeight = imagesy($QR)/2;
$logoWidth = imagesx($logo);
$logoHeight = imagesy($logo);
......@@ -119,7 +119,7 @@
$imgWidth = $qrWidth;
$imgHeight = $logoHeight/$scale;
imagecopyresampled($QR,$logo,$imgWidth,$qrHeight,0,0,$imgWidth,$imgHeight,$logoWidth,$logoHeight);
imagecopyresampled($QR,$logo,125,120,0,0,$imgWidth,$imgHeight,$logoWidth,$logoHeight);
imagepng($QR, $savePath);
return $savePath;
......
......@@ -538,10 +538,23 @@ class Api_model extends CI_Model {
return $res;
}
function imageResize($path,$size){
$this->load->library('image_lib');
$config['width'] = $size['width'];
$config['height'] = $size['height'];
$config['new_image'] = $path;
$config['source_image'] = $path;
$config['create_thumb'] = FALSE;
$config['image_library'] = 'gd2';
$config['maintain_ratio'] = TRUE;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
}
public function update_profile($data) {
try{
$user_id = $this->auth_token_get($data['auth_token']);
$img_error = 0;
if($user_id > 0) {
$post_data = $data;
unset($post_data['file']);
......@@ -551,60 +564,25 @@ class Api_model extends CI_Model {
$post_data['profile_city'] = $post_data['city'];
unset($post_data['city']);
}
if(isset($data['file'])){
$imgName = $data['file']['name'];
$imgNameArr = explode('.',$imgName);
$imgExt = strtolower($imgNameArr[1]);
if($imgExt=='png' || $imgExt=='jpeg' || $imgExt == 'jpg' || $imgExt == 'gif'){
$imgPath = 'assets/uploads/user/CUST_'.$user_id.'.jpg';
$imgQRPath = 'assets/uploads/user/CUST_QR_'.$user_id.'.jpg';
$imgFramePath = 'assets/images/bitmojiFrame.jpg';
move_uploaded_file($data['file']["tmp_name"],"./".$imgPath);
$usrImage = imagecreatefrompng($imgPath);
$imgFrame = imagecreatefromjpeg($imgFramePath);
imagecopy($imgFrame,$usrImage,(imagesx($imgFrame)/2)-(imagesx($usrImage)/2),(imagesy($imgFrame)/2)-(imagesy($usrImage)/2),0,0,imagesx($usrImage),imagesy($usrImage));
imagesavealpha($imgFrame, true);
imagepng($imgFrame,$imgPath,0);
genQRcode(encode_param($user_id),$imgQRPath,$imgPath);
$post_data['profile_image'] = $imgPath;
$post_data['profile_image_qr'] = $imgQRPath;
$state=$this->db->where('customer_id',$user_id)->update('customer',$post_data);
if($state){
$img_error = 1;
} else {
$res = array('status'=>0,'message'=>'Profile update failed','code'=>'ER32');
}
} else {
$res = array('status'=>0,'message'=>'Invalid Image type','code'=>'ER31');
}
} else {
$state = $this->db->where('customer_id',$user_id)->update('customer',$post_data);
if($state){
$img_error = 1;
} else {
$res = array('status'=>0,'message'=>'Profile update failed','code'=>'ER32');
}
}
if($img_error == 1) {
$this->db->select('customer.name,customer.dob,customer.phone,customer.email,
customer.profile_image AS image,customer.gender,
users.id AS userId, customer.profile_city AS city');
customer.profile_image AS image,customer.gender,users.id AS userId,
customer.profile_image_qr,customer.profile_city AS city');
$this->db->where('users.id',$user_id);
$this->db->from('users');
$this->db->join('customer','customer.customer_id = users.id');
$result = $this->db->get()->row();
if($result){
$result->dob = (!empty($result->dob))?date("m/d/Y", ($result->dob)/1000):'';
$res = array('status'=>1,'data'=>$result);
} else {
$res = array('status'=>0,'message'=>'Invalid user','code'=>'ER19');
}
} else {
$res = array('status'=>0,'message'=>'Profile update failed','code'=>'ER32');
}
} else {
$res = array('status'=>0,'message'=>'Invalid user','code'=>'ER19');
......
......@@ -954,11 +954,11 @@ class Webservice_model extends CI_Model {
public function update_profile($data) {
try{
$user_id = $this->auth_token_get($data['auth_token']);
$img_error = 0;
if($user_id > 0) {
$post_data = $data;
unset($post_data['file']);
unset($post_data['auth_token']);
if(isset($data['email'])){
$this->db->select('customer.email');
$this->db->where('customer.email',$data['email']);
......@@ -972,45 +972,59 @@ class Webservice_model extends CI_Model {
return $res;
}
}
if(isset($data['file'])){
$imgName = $data['file']['name'];
$imgNameArr = explode('.',$imgName);
$imgExt = strtolower($imgNameArr[1]);
if($imgExt=='png' || $imgExt=='jpeg' || $imgExt == 'jpg' || $imgExt == 'gif'){
$imgPath = 'assets/uploads/user/CUST_'.$user_id.'.'.$imgExt;
$imgPath = 'assets/uploads/user/CUST_'.$user_id.'.png';
$imgQRPath = 'assets/uploads/user/CUST_QR_'.$user_id.'.png';
$imgFramePath = 'assets/images/bitmojiFrame.png';
move_uploaded_file($data['file']["tmp_name"],"./".$imgPath);
$this->imageResize($imgPath,array('width'=>'300','height'=>'300'));
$usrImage = imagecreatefrompng($imgPath);
$imgFrame = imagecreatefrompng($imgFramePath);
imagecopy($imgFrame,$usrImage,(imagesx($imgFrame)/2)-(imagesx($usrImage)/2),(imagesy($imgFrame)/2)-(imagesy($usrImage)/2),0,0,imagesx($usrImage),imagesy($usrImage));
imagesavealpha($imgFrame, true);
imagepng($imgFrame,$imgPath,0);
genQRcode(encode_param($user_id),$imgQRPath,$imgPath);
$post_data['profile_image'] = $imgPath;
$post_data['profile_image_qr'] = $imgQRPath;
$state = $this->db->where('customer_id',$user_id)->update('customer',$post_data);
if($state){
$img_error = 1;
} else {
$res = array('status'=>0,'message'=>'Profile update failed','code'=>'ER32');
if(!$state){
return array('status'=>0,'message'=>'Profile update failed','code'=>'ER32');
}
} else {
$res = array('status'=>0,'message'=>'Invalid Image type','code'=>'ER41');
return array('status'=>0,'message'=>'Invalid Image type','code'=>'ER41');
}
} else {
$state = $this->db->where('customer_id',$user_id)->update('customer',$post_data);
if($state){
$img_error = 1;
} else {
$res = array('status'=>0,'message'=>'Profile update failed','code'=>'ER32');
if(!$state){
return array('status'=>0,'message'=>'Profile update failed','code'=>'ER32');
}
}
if($img_error == 1) {
$this->db->select('customer.name,customer.dob,customer.phone,customer.email,customer.profile_image AS image,customer.gender,users.id AS userId, customer.city');
$this->db->select('customer.name,customer.dob,customer.phone,customer.email,customer.gender,
customer.profile_image AS image,users.id AS userId, customer.city,
customer.profile_image_qr AS customer_qr');
$this->db->where('users.id',$user_id);
$this->db->from('users');
$this->db->join('customer','customer.customer_id = users.id');
$result = $this->db->get()->row();
if($result){
$res = array('status'=>1,'data'=>$result);
} else {
$res = array('status'=>0,'message'=>'Invalid user','code'=>'ER19');
}
}
} else {
$res = array('status'=>0,'message'=>'Invalid user','code'=>'ER19');
}
......@@ -1975,5 +1989,19 @@ class Webservice_model extends CI_Model {
$res = array('status'=>0,'message'=>'Invalid user','code'=>'ER19');
}
}
public function imageResize($path,$size){
$this->load->library('image_lib');
$config['width'] = $size['width'];
$config['height'] = $size['height'];
$config['new_image'] = $path;
$config['source_image'] = $path;
$config['create_thumb'] = FALSE;
$config['image_library'] = 'gd2';
$config['maintain_ratio'] = TRUE;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
}
}
?>
assets/images/qr-cod-icon.png

10.2 KB | W: | H:

assets/images/qr-cod-icon.png

11.8 KB | W: | H:

assets/images/qr-cod-icon.png
assets/images/qr-cod-icon.png
assets/images/qr-cod-icon.png
assets/images/qr-cod-icon.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment