TP利用水印进行图片合成

public function shopCode($store_user_id,$user_id,$data_send,$savepath,$status,$class_id) {
    $img_path = ROOT . 'style/kong.png';
    $user_shop_model = new \Common\Model\UserShopModel();
    $shop_data = $user_shop_model->where("user_id =".$store_user_id)->find();             
    $ware_model = new \Common\Model\WareModel();
    $ware_condition['store_id'] = $shop_data['store_id'];
    $ware_data = $ware_model->getList($ware_condition, 9);
    $store_model = new \Common\Model\StoreModel();

    $store_condition['store_status'] = 1;
    $store_condition['is_on_hover'] = 1;
    $store_condition['start_time'] = ['LT', TIME];
    $store_condition['end_time'] = ['GT', TIME];
    $store_data = $store_model->getList($store_condition,9);

    $shop_desc = $store_model->where("store_id =".$shop_data['store_id'])->getField('shop_desc');
    if (empty($shop_desc)) {
        $shop_desc = $user_shop_model->where("user_id =".$store_user_id)->getField('shop_signature');
    }
    
    // $arr = str_split($shop_desc,48);
    $shop_desc = str_replace("\n", "", $shop_desc);
    $len = ceil(strlen($shop_desc)/48);
    for ($i=0; $i < $len; $i++) { 
        $arr[$i] = mb_substr($shop_desc,0+16*$i,16);
    }
    if (!empty($arr[3])&&strlen($arr[3])>39) {
        $arr[3] = mb_substr($arr[3],0,13);
        $arr[3] .= '...';
    }
    
    if (strlen($shop_data['shop_name'])>33) {
        $shop_data['shop_name'] = substr($shop_data['shop_name'],0,30);
        $shop_data['shop_name'] .= '...';
    }
    $userImage = new \Common\Model\UserImage();
    $other_dir = $userImage::getOtherDir();
    $dir = $userImage->getTempDir($store_user_id);

    $file_model = new \Common\Model\FileModel();
    $file_arr = $file_model->uploadCodeOss($data_send,$savepath);
    $f_logo = $user_shop_model->where("user_id =".$store_user_id)->getField('shop_logo');
    $ext = pathinfo($f_logo);
    if ($ext['extension'] !== 'png') {
        file_put_contents(ROOT . $dir.'head'.$user_id.'.jpg', file_get_contents($f_logo));
        $f_logo = ROOT . $dir.'head'.$user_id.'.jpg';
    } 
    $circle_path = ROOT . $dir.'pic'.$user_id.".png";
    $logo = $this->createRoundImg($f_logo,$circle_path);       
    $QR = CDN_HOST.$file_arr['file_path'];

    // $circle_white = ROOT . $dir.'picwhite'.$user_id.".png";
    // $ci = $this->createRoundImg(ROOT . 'style/white.png',$circle_white);
    // $white_QR = ROOT . $dir.'whitecode'.$store_user_id.".png"; 
    // $wh = $this->codeImg($circle_white ,$QR ,$white_QR);

    $pathimg = ROOT . $dir.'code'.$store_user_id.".png";
    $result_code = $this->codeImg($logo ,$QR ,$pathimg);
    $result['circle_path'] = $circle_path;
    $result['pathimg'] = $pathimg;

    $res_image = ROOT . $dir.'user_code.png'; 
    $img = new \Think\Image();
    
    $code_re = ROOT . $dir.'codes.png';
    $logo_re = ROOT . $dir.'logos.png';
    $img->open($result['pathimg'])
                ->thumb(150, 150, $img::IMAGE_THUMB_SCALE)//等比例缩放
                ->save($code_re, 'png', 80);
    $img->open($result['circle_path'])
                ->thumb(65, 65, $img::IMAGE_THUMB_SCALE)//等比例缩放
                ->save($logo_re, 'png', 80);
    
    foreach ($store_data['list'] as $k => $v) {
        if (empty($v['brand_logo'])) {
            file_put_contents(ROOT . $dir.'old_goods'.$k.'.png', file_get_contents($img_path));
        } else{
            file_put_contents(ROOT . $dir.'old_goods'.$k.'.png', file_get_contents(CDN_HOST.$v['brand_logo']));
        }
        
        $goods_re = ROOT . $dir.'goods'.$k.'.png';
        $goods_img = ROOT . $dir.'old_goods'.$k.'.png';
        $img->open($goods_img)
                ->thumb(180, 180, $img::IMAGE_THUMB_SCALE)//等比例缩放
                ->save($goods_re, 'png', 80);
        $goods_path[$k] = $goods_re;
    }
    if (count($goods_path)<9) {
        for ($i=count($goods_path)-1; $i < 9; $i++) { 
            file_put_contents(ROOT . $dir.'old_goods'.$i.'.png', file_get_contents($img_path));
            $goods_res = ROOT . $dir.'goods'.$i.'.png';
            $goods_imgs = ROOT . $dir.'old_goods'.$i.'.png';
            $img->open($goods_imgs)
                ->thumb(180, 180, $img::IMAGE_THUMB_SCALE)//等比例缩放
                ->save($goods_res, 'png', 80);
        }
    }
    $new_image = $img->open($img_path)
            ->water($code_re, array(430, 638), 90) 
            ->water($logo_re, array(20, 638), 100)
            ->water(ROOT . $dir.'goods0.png', array(20, 20), 100)
            ->water(ROOT . $dir.'goods1.png', array(210, 20), 100)  
            ->water(ROOT . $dir.'goods2.png', array(400, 20), 100)  
            ->water(ROOT . $dir.'goods3.png', array(20, 210), 100)  
            ->water(ROOT . $dir.'goods4.png', array(210, 210), 100)  
            ->water(ROOT . $dir.'goods5.png', array(400, 210), 100)  
            ->water(ROOT . $dir.'goods6.png', array(20, 400), 100)  
            ->water(ROOT . $dir.'goods7.png', array(210, 400), 100)  
            ->water(ROOT . $dir.'goods8.png', array(400, 400), 100)    
            ->text("长按识别小程序码", $other_dir . 'msyh.ttf', 14, '#919191', array(430, 818))
            ->text($shop_data['shop_name'], $other_dir . 'msyh.ttf', 20, '#303030', array(100, 650)) 
            ->text($arr[0], $other_dir . 'msyh.ttf', 16, '#7A7A7A', array(20, 728)) 
            ->text($arr[1], $other_dir . 'msyh.ttf', 16, '#7A7A7A', array(20, 758)) 
            ->text($arr[2], $other_dir . 'msyh.ttf', 16, '#7A7A7A', array(20, 788)) 
            ->text($arr[3], $other_dir . 'msyh.ttf', 16, '#7A7A7A', array(20, 818))
            ->save($res_image, 'png', 80);
    // foreach ($ware_data['list'] as $key => $value) {
    //      unlink(ROOT . $dir.'goods'.$key.'.png');
    //      unlink(ROOT . $dir.'old_goods'.$key.'.png');
    // }
    for ($i=0; $i < 9; $i++) { 
        unlink(ROOT . $dir.'goods'.$i.'.png');
        unlink(ROOT . $dir.'old_goods'.$i.'.png');
    }
    unlink($code_re);
    unlink($logo_re);
    $file_model = new \Common\Model\FileModel();
    $PSize = filesize($res_image);
    $picturedata = fread(fopen($res_image, "r"), $PSize);
    $file_arr_new = $file_model->uploadCodeOss($picturedata,$savepath);

    $code_data = array(
        'store_user_id' => $store_user_id,
        'user_id' => $user_id,
        'status' => $status,
        'class_id' => $class_id,
        'code' => $file_arr_new['file_path'],
        'old_code' => $file_arr['file_path'],
        );
    M('code_log')->add($code_data);
    unlink($circle_path);
    unlink($pathimg);
    unlink($f_logo);
    unlink(ROOT . $dir.'fanglogo.png');
    
    return $file_arr_new['file_path'];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值