68 lines
2.4 KiB
PHP
68 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 协议签名
|
|
*/
|
|
use Gregwar\Image\Image;
|
|
class Sign_entity{
|
|
|
|
private $ci;
|
|
private $comp_img = 'https://qimg.haodian.cn/hdi/2021/07/f2308e9066d290eb/79063515aefc302f.png'; //公司印章图片地址
|
|
|
|
public function __construct($params=[]){
|
|
$this->ci = & get_instance();
|
|
$params['comp_img'] && $this->comp_img = $params['comp_img'];
|
|
}
|
|
|
|
/**
|
|
* 图片签名
|
|
* @param $orgin_url string 签名图片地址
|
|
* @param $user_image string 用户签名图片地址
|
|
* @param $width int 用户签名x坐标
|
|
* @param $height int 用户签名y坐标
|
|
* @param $o_width int 公司签名x坐标
|
|
* @param $o_height int 公司签名y坐标
|
|
* @param $need_c boolean 是否需要公司章
|
|
* @param $s_path string 图片保存地址
|
|
* return string 返回合成后图片地址
|
|
*/
|
|
public function merge($origin_url,$user_file,$width,$height,$o_width='',$o_height='',$need_c=true,$s_path='' ){
|
|
$arrContextOptions=array(
|
|
"ssl"=>array(
|
|
"verify_peer"=>false,
|
|
"verify_peer_name"=>false,
|
|
),
|
|
);
|
|
//临时保存签名图片
|
|
if (!file_exists(FCPATH.'/temp')){
|
|
$oldumask = umask(0);
|
|
mkdir(FCPATH.'/temp', 0777, true);
|
|
umask($oldumask);
|
|
}
|
|
$file_name = time().rand(1,9999999);
|
|
!$s_path && $s_path = FCPATH.'temp/'.md5('sign'.$file_name).'.jpg';
|
|
|
|
$yhdata = file_get_contents($user_file,false,stream_context_create($arrContextOptions));
|
|
$yh_image = Image::fromData($yhdata)->cropResize(150,150)->rotate(90);
|
|
|
|
|
|
//原始签名文件
|
|
$data = file_get_contents($origin_url,false,stream_context_create($arrContextOptions));
|
|
$imgobj = Image::fromData($data);
|
|
if($need_c){
|
|
!$o_height && $o_height = $height;
|
|
//公司
|
|
$gs_data = file_get_contents($this->comp_img,false,stream_context_create($arrContextOptions));
|
|
$gs_image = Image::fromData($gs_data)->cropResize(200,200);
|
|
$imgobj->merge($gs_image,$o_width,$o_height);
|
|
}
|
|
$imgobj->merge($yh_image,$width,$height)->save($s_path);
|
|
if(file_exists($s_path)){
|
|
return str_replace(FCPATH,'',$s_path);
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|