<?php

/**
 * $Author ：PHPYUN开发团队
 *
 * 官网: http://www.phpyun.com
 *
 * 版权所有 2009-2021 宿迁鑫潮信息技术有限公司，并保留所有权利。
 *
 * 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */

class whb_model extends model
{

    public function getWhbList($whereData = array(), $data = array())
    {

        $list   =   array();

        if (!empty($whereData)) {

            $data['field']  =   empty($data['field']) ? '*' : $data['field'];

			if(!isset($whereData['orderby'])){
                $whereData['orderby']   =   array('num,desc', 'sort,desc');
            }

            $list           =   $this->select_all('admin_jobwhb', $whereData, $data['field']);

			$style  =   array();
            foreach ($list as $key => $value) {

                if ($value['pic']) {
                    $list[$key]['pic_n']    =   checkpic($value['pic']);
                }
                if ($data['only']==1){
                    if (!in_array($value['style'], $style)){
                        $style[]    =   $value['style'];
                    }else{
                        unset($list[$key]);
                    }
                }
            }
        }
        return $list;
    }

    public function getWhb($whereData = array(), $data = array())
    {

        if (!empty($whereData)) {

            $data['field']  =   empty($data['field']) ? '*' : $data['field'];

            $whb            =   $this->select_once('admin_jobwhb', $whereData, $data['field']);

            if (isset($whb['pic'])) {

                $whb['pic_n']   =   checkpic($whb['pic']);
            }
            return $whb;
        }
    }

    public function updateWhb($updata = array(), $whereData = array())
    {

        if (!empty($whereData)) {

            $return = $this->update_once('admin_jobwhb', $updata, $whereData);
        }
    }

    public function delWhb($whereData = array())
    {

        if (!empty($whereData)) {

            $return =   $this->delete_all('admin_jobwhb', $whereData, '');
        }
    }

    public function setWhb($updata = array(), $whereData = array())
    {

        if (trim($updata['name']) == '') {

            return array('msg' => '海报名称不能为空！', 'errcode' => 8);
        }

        if (!empty($whereData)) {

            $return['id']   =   $this->update_once('admin_jobwhb', $updata, $whereData);

            $return['msg']  =   '微海报更新';
        } else {

            $return['id']   =   $this->insert_into('admin_jobwhb', $updata);

            $return['msg']  =   '微海报添加';
        }

        $return['errcode']  =   $return['id'] ? '9' : '8';

        $return['msg']      =   $return['id'] ? $return['msg'] . '成功！' : $return['msg'] . '失败！';

        return $return;
    }

    function getJobHb($data = array())
    {

        if (!empty($data)) {

            $whb    =   $this->getWhb(array('id' => $data['hb']));

            if (!isset($this->config['sy_oss']) || $this->config['sy_oss'] != 1) {

                $imgFile    =   str_replace($this->config['sy_weburl'].'/data/', DATA_PATH, $whb['pic_n']);
            } else {

                $imgFile    =   $whb['pic_n'];
            }

            $jobId  =   $data['id'];

            $job    =   $this->getJobInfo(array('id' => $jobId, 'status' => 0, 'state' => 1), array('hb' => 1));

            if (!empty($job) && is_array($job)) {

                $jobCity    =   !empty($job['job_city_two']) ? $job['job_city_two'] : $job['job_city_one'];
                $jobExp     =   !empty($job['job_exp']) ? $job['job_exp'] : '经验不限';
                $jobEdu     =   !empty($job['job_edu']) ? $job['job_edu'] : '学历不限';

                if (!isset($this->config['sy_oss']) || $this->config['sy_oss'] != 1) {
                    $job['com_logo_n']  =   str_replace($this->config['sy_weburl'] . '/data/', DATA_PATH, $job['com_logo_n']);
                }

                $imgConfig  =   array(
                    'text'  =>  array(
                        array(
                            'text'      =>  mb_substr($job['name'], 0, 16, 'utf-8'),
                            'left'      =>  116,
                            'top'       =>  1499,
                            'fontSize'  =>  '40px',         //字号
                            'fontColor' =>  '0,0,0'         //字体颜色
                        ),
                        array(
                            'text'      =>  $job['job_salary'],
                            'left'      =>  116,
                            'top'       =>  1605,
                            'fontSize'  =>  '40px',         //字号
                            'fontColor' =>  '255,0,0'       //字体颜色
                        ),
                        array(
                            'text'      =>  mb_substr($job['com_name'], 0, 15, 'utf-8'),
                            'left'      =>  240,
                            'top'       =>  1710,
                            'fontSize'  =>  '28px',         //字号
                            'fontColor' =>  '51,51,51'         //字体颜色
                        ),

                        array(
                            'text'      =>  mb_substr($jobCity . ' - ' . $jobExp . ' - ' . $jobEdu . '学历', 0, 35, 'utf-8'),
                            'left'      =>  240,
                            'top'       =>  1760,
                            'fontSize'  =>  '22px',         //字号
                            'fontColor' =>  '102,102,102',  //字体颜色
                        ),
                        array(
                            'text'      =>  '长按识别二维码',
                            'left'      =>  782,
                            'top'       =>  1760,
                            'fontSize'  =>  '22px',         //字号
                            'fontColor' =>  '102,102,102',  //字体颜色
                        )
                    ),
                    'image' =>  array(
                        array(
                            'url'       =>  Url('wap', array('c' => 'ajax', 'a' => 'pubqrcode', 'toc' => 'job', 'toa' => 'comapply', 'toid' => $jobId)),        //二维码资源
                            'stream'    =>  0,
                            'left'      =>  790,
                            'top'       =>  -190,
                            'right'     =>  0,
                            'bottom'    =>  0,
                            'width'     =>  180,
                            'height'    =>  180,
                            'opacity'   =>  100
                        ),
                        array(
                            'url'       =>  $job['com_logo_n'],  //  企业LOGO
                            'stream'    =>  0,
                            'left'      =>  116,
                            'top'       =>  -150,
                            'right'     =>  0,
                            'bottom'    =>  0,
                            'width'     =>  100,
                            'height'    =>  100,
                            'opacity'   =>  100
                        )
                    ),
                    'background'    =>  $imgFile    //背景图
                );

                if($this->config['sy_haibao_web_type'] == 1){ // 自定义网站名称
                    $imgConfig['text'][] = array(
                        'text'      =>  $this->config['sy_haibao_web_name'],
                        'left'      =>  50,
                        'top'       =>  140,
                        'fontSize'  =>  '60px',         //字号
                        'fontColor' =>  '255,255,255'   //字体颜色
                    );
                } elseif ($this->config['sy_haibao_web_type'] == 2){
                    $web_logo = $this->config['sy_ossurl'] . '/' . $this->config['sy_haibao_web_logo'];
                    $imgsize = @getimagesize($web_logo);
                    if($imgsize){ // 图片宽高获取成功
                        $imgConfig['image'][] = array(
                            'url'       =>  $web_logo,
                            'stream'    =>  0,
                            'left'      =>  50,
                            'top'       =>  70,
                            // 'right'     =>  0,
                            // 'bottom'    =>  0,
                            'width'     =>  $imgsize[0],
                            'height'    =>  $imgsize[1],
                            'opacity'   =>  100,
                            'c_opacity' => 1,
                        );
                    }
                }

                echo $this->createPoster($imgConfig);
            }
        }
    }

    private function getJobInfo($where, $data)
    {

        require_once('job.model.php');
        $JobM   =   new job_model($this->db, $this->def);
        return $JobM->getInfo($where, $data);
    }

    private function getJobList($where, $data)
    {

        require_once('job.model.php');
        $JobM   =   new job_model($this->db, $this->def);
        return $JobM->getHbJobList($where, $data);
    }

    function getComHb($data = array())
    {

        if (!empty($data)) {

            $comId      =   $data['uid'];

            $com        =   $this->getComInfo($comId, array('field' => 'uid, name, shortname, logo, mun, hy', 'logo' => 1, 'hb' => 1));
            if (!empty($com['shortname'])){

                $com['name']    =   $com['shortname'];
            }

            if ($data['hb']){

                $whb    =   $this->getWhb(array('id' => $data['hb']));

            }else{

                if ($data['jobids']){

                    $jobIdA =   explode(',', $data['jobids']);
                    $num    =   count($jobIdA);
                }else{

                    $num    =   $this->select_num('company_job', array('state' => 1, 'status' => '0', 'r_status' => 1, 'uid' => $comId));
                }

                $whb    =   $this->getWhb(array('style' => $data['style'], 'num' => $num));

                if (empty($whb)){

                    $whb    =   $this->getWhb(array('style' => $data['style'], 'num' => array('<>', $num)));
                }
            }

            if (!isset($this->config['sy_oss']) || $this->config['sy_oss'] != 1) {

                $imgFile    =   str_replace($this->config['sy_weburl'].'/data/', DATA_PATH, $whb['pic_n']);
            } else {

                $imgFile    =   $whb['pic_n'];
            }

            $num    =   $whb['num'];

            if (isset($data['jobids'])){

                $jobWhere   =   array(
                    'uid'       =>  $comId,
                    'id'        =>  array('in', $data['jobids']),
                    'orderby'   =>  'lastupdate, desc',
                    'limit'     =>  $num
                );
            }else{
                $jobWhere   =   array(
                    'uid'       =>  $comId,
                    'state'     =>  1,
                    'status'    =>  0,
                    'r_status'  =>  1,
                    'orderby'   =>  'lastupdate, desc',
                    'limit'     =>  $num
                );
            }

            $jobs   =   $this->getJobList($jobWhere, array('field' => 'id, name, minsalary, maxsalary', 'hb' => 1));

            if (!empty($com) && is_array($com)) {

                $comMun =   !empty($com['mun_n']) ? $com['mun_n'] : '';
                $comHy  =   !empty($com['hy_n']) ? $com['hy_n'] : '';

                if (!isset($this->config['sy_oss']) || $this->config['sy_oss'] != 1) {
                    $com['logo_n']  =   str_replace($this->config['sy_weburl'] . '/data/', DATA_PATH, $com['logo']);
                }else{
                    $com['logo_n']  =   checkpic($com['logo']);
                }

                $jobOneName =   $jobTwoName = $jobThreeName = $jobFourName = $jobFiveName = $jobSixName = '';
                $jobOneXZ =   $jobTwoXZ = $jobThreeXZ = $jobFourXZ = $jobFiveXZ = $jobSixXZ = '';

                foreach ($jobs as $jk => $jv) {

                    if (strlen($jv['name']) > 24){

                        $jv['name']     =   mb_substr($jv['name'].$jv['name'], 0, 8, 'utf-8').'...';
                    }
                    if ($jk == 0){
                        $jobOneName =   $jv['name'];
                        $jobOneXZ =   $jv['job_salary'];
                    }
                    if ($jk == 1){
                        $jobTwoName =   $jv['name'];
                        $jobTwoXZ =   $jv['job_salary'];
                    }
                    if ($jk == 2){
                        $jobThreeName =   $jv['name'];
                        $jobThreeXZ =   $jv['job_salary'];
                    }
                    if ($jk == 3){
                        $jobFourName =   $jv['name'];
                        $jobFourXZ =   $jv['job_salary'];
                    }
                    if ($jk == 4){
                        $jobFiveName =   $jv['name'];
                        $jobFiveXZ =   $jv['job_salary'];
                    }
                    if ($jk == 5){
                        $jobSixName =   $jv['name'];
                        $jobSixXZ =   $jv['job_salary'];
                    }
                }

                $textArr    =   array(
                    array(
                        'text'      =>  mb_substr($com['name'], 0, 12, 'utf-8'),
                        'left'      =>  250,
                        'top'       =>  -350,
                        'fontSize'  =>  '30px',         //字号
                        'fontColor' =>  '0,0,0'         //字体颜色
                    ),
                    array(
                        'text'      =>  $comMun.' | '.$comHy,
                        'left'      =>  250,
                        'top'       =>  -280,
                        'fontSize'  =>  '20px',         //字号
                        'fontColor' =>  '128,128,128'         //字体颜色
                    )
                );

                if (isset($jobOneName)){
                    array_push($textArr,
                        array(
                            'text'      =>  $jobOneName,
                            'left'      =>  120,
                            'top'       =>  -570,
                            'fontSize'  =>  '40px',
                            'fontColor' =>  '0,0,0'
                        ),
                        array(
                            'text'      =>  $jobOneXZ,
                            'left'      =>  -450,
                            'top'       =>  -570,
                            'fontSize'  =>  '30px',
                            'fontColor' =>  '255,0,0'
                        )
                    );
                }


                if (isset($jobTwoName) && $whb['num'] >= 2){

                    array_push($textArr,
                        array(
                            'text'      =>  $jobTwoName,
                            'left'      =>  120,
                            'top'       =>  -670,
                            'fontSize'  =>  '40px',
                            'fontColor' =>  '0,0,0'
                        ),

                        array(
                            'text'      =>  $jobTwoXZ,
                            'left'      =>  -450,
                            'top'       =>  -670,
                            'fontSize'  =>  '30px',
                            'fontColor' =>  '255,0,0'
                        )
                    );
                }
                if (isset($jobThreeName) && $whb['num'] >= 3){
                    array_push($textArr,
                        array(
                            'text'      =>  $jobThreeName,
                            'left'      =>  120,
                            'top'       =>  -770,
                            'fontSize'  =>  '40px',
                            'fontColor' =>  '0,0,0'
                        ),

                        array(
                            'text'      =>  $jobThreeXZ,
                            'left'      =>  -450,
                            'top'       =>  -770,
                            'fontSize'  =>  '30px',
                            'fontColor' =>  '255,0,0'
                        )
                    );
                }
                if (isset($jobFourName) && $whb['num'] >= 4){
                    array_push($textArr,
                        array(
                            'text'      =>  $jobFourName,
                            'left'      =>  120,
                            'top'       =>  -870,
                            'fontSize'  =>  '40px',
                            'fontColor' =>  '0,0,0'
                        ),

                        array(
                            'text'      =>  $jobFourXZ,
                            'left'      =>  -450,
                            'top'       =>  -870,
                            'fontSize'  =>  '30px',
                            'fontColor' =>  '255,0,0'
                        )
                    );
                }
                if (isset($jobFiveName) && $whb['num'] >= 5){
                    array_push($textArr,
                        array(
                            'text'      =>  $jobFiveName,
                            'left'      =>  120,
                            'top'       =>  -970,
                            'fontSize'  =>  '40px',
                            'fontColor' =>  '0,0,0'
                        ),

                        array(
                            'text'      =>  $jobFiveXZ,
                            'left'      =>  -450,
                            'top'       =>  -970,
                            'fontSize'  =>  '30px',
                            'fontColor' =>  '255,0,0'
                        )
                    );
                }
                if (isset($jobSixName) && $whb['num'] == 6){
                    array_push($textArr,
                        array(
                            'text'      =>  $jobSixName,
                            'left'      =>  120,
                            'top'       =>  -1070,
                            'fontSize'  =>  '40px',
                            'fontColor' =>  '0,0,0'
                        ),

                        array(
                            'text'      =>  $jobSixXZ,
                            'left'      =>  -450,
                            'top'       =>  -1070,
                            'fontSize'  =>  '30px',
                            'fontColor' =>  '255,0,0'
                        )
                    );
                }

                $imageArr = array(
                    array(
                        'url'       =>  Url('wap', array('c' => 'ajax', 'a' => 'pubqrcode', 'toc' => 'company', 'toa' => 'show', 'toid' => $comId)),        //二维码资源
                        'stream'    =>  0,
                        'left'      =>  -150,
                        'top'       =>  -240,
                        'right'     =>  0,
                        'bottom'    =>  0,
                        'width'     =>  160,
                        'height'    =>  160,
                        'opacity'   =>  100
                    ),
                    array(
                        'url'       =>  $com['logo_n'],  //  企业LOGO
                        'stream'    =>  0,
                        'left'      =>  120,
                        'top'       =>  -270,
                        'right'     =>  0,
                        'bottom'    =>  0,
                        'width'     =>  120,
                        'height'    =>  120,
                        'opacity'   =>  100
                    )
                );

                if($this->config['sy_haibao_web_type'] == 1){ // 自定义网站名称
                    $textArr[] = array(
                        'text'      =>  $this->config['sy_haibao_web_name'],
                        'left'      =>  66,
                        'top'       =>  140,
                        'fontSize'  =>  '60px',         //字号
                        'fontColor' =>  '255,255,255'   //字体颜色
                    );
                } elseif ($this->config['sy_haibao_web_type'] == 2){
                    $web_logo = $this->config['sy_ossurl'] . '/' . $this->config['sy_haibao_web_logo'];
                    $imgsize = @getimagesize($web_logo);
                    if($imgsize){ // 图片宽高获取成功
                        $imageArr[] = array(
                            'url'       =>  $web_logo,
                            'stream'    =>  0,
                            'left'      =>  66,
                            'top'       =>  80,
                            // 'right'     =>  0,
                            // 'bottom'    =>  0,
                            'width'     =>  $imgsize[0],
                            'height'    =>  $imgsize[1],
                            'opacity'   =>  100,
                            'c_opacity' => 1,
                        );
                    }
                }

                $imgConfig  =   array(
                    'text'  =>  $textArr,
                    'image' =>  $imageArr,
                    'background'    =>  $imgFile    //背景图
                );

                echo $this->createPoster($imgConfig);
            }
        }
    }

    private function getComInfo($where, $data)
    {

        require_once('company.model.php');
        $ComM   =   new company_model($this->db, $this->def);
        return $ComM->getInfo($where, $data);
    }

    function mbStrSplit($string, $len = 1)
    {

        $start  =    0;
        $strlen =   mb_strlen($string);

        while ($strlen) {

            $array[]    =   mb_substr($string, $start, $len, "utf8");

            $string     =   mb_substr($string, $len, $strlen, "utf8");

            $strlen     =   mb_strlen($string);
        }

        return $array;
    }

    function getLogoHb($data = array())
    {

        $hb =   $data['hb'];

        $bg =   DATA_PATH.'upload/whb/logo/'.$hb.'.png';

        $str    =   $this->mbStrSplit($data['text']);

        if ($str[3]){
            $textArr    =   array(
                array(
                    'text'      =>  $str[0],
                    'left'      =>  10,
                    'top'       =>  90,
                    'fontSize'  =>  '60px',         //字号
                    'fontColor' =>  '255,255,255'   //字体颜色
                ),
                array(
                    'text'      =>  $str[1],
                    'left'      =>  110,
                    'top'       =>  90,
                    'fontSize'  =>  '60px',         //字号
                    'fontColor' =>  '255,255,255'   //字体颜色
                ),
                array(
                    'text'      =>  $str[2],
                    'left'      =>  10,
                    'top'       =>  170,
                    'fontSize'  =>  '60px',         //字号
                    'fontColor' =>  '255,255,255'   //字体颜色
                ),
                array(
                    'text'      =>  $str[3],
                    'left'      =>  110,
                    'top'       =>  170,
                    'fontSize'  =>  '60px',         //字号
                    'fontColor' =>  '255,255,255'   //字体颜色
                )
            );
        }else if ($str[2]){
            $textArr    =   array(
                array(
                    'text'      =>  $str[0],
                    'left'      =>  10,
                    'top'       =>  110,
                    'fontSize'  =>  '40px',         //字号
                    'fontColor' =>  '255,255,255'   //字体颜色
                ),
                array(
                    'text'      =>  $str[1],
                    'left'      =>  70,
                    'top'       =>  110,
                    'fontSize'  =>  '40px',         //字号
                    'fontColor' =>  '255,255,255'   //字体颜色
                ),
                array(
                    'text'      =>  $str[2],
                    'left'      =>  130,
                    'top'       =>  110,
                    'fontSize'  =>  '40px',         //字号
                    'fontColor' =>  '255,255,255'   //字体颜色
                )
            );
        } else {

            $textArr    =   array(
                array(
                    'text'      =>  $str[0],
                    'left'      =>  20,
                    'top'       =>  120,
                    'fontSize'  =>  '60px',         //字号
                    'fontColor' =>  '255,255,255'   //字体颜色
                ),
                array(
                    'text'      =>  $str[1],
                    'left'      =>  105,
                    'top'       =>  120,
                    'fontSize'  =>  '60px',         //字号
                    'fontColor' =>  '255,255,255'   //字体颜色
                )
            );
        }

        $imgConfig  =   array(

            'text'          =>  $textArr,
            'background'    =>  $bg    //背景图
        );

        if (isset($data['out']) && $data['out'] == 1){
            $imgConfig['out']   =   1;
        }

        echo $this->createPoster($imgConfig);

    }

    function createPoster($config = array())
    {

        if (!isset($config['out'])){

            header("Content-type: image/png");
        }

        $imageDefault   =   array(
            'left'      =>  0,
            'top'       =>  0,
            'right'     =>  0,
            'bottom'    =>  0,
            'width'     =>  100,
            'height'    =>  100,
            'opacity'   =>  100
        );
        $textDefault    =   array(
            'text'      =>  '',
            'left'      =>  0,
            'top'       =>  0,
            'fontSize'  =>  32,                 //  字号
            'fontColor' =>  '255,255,255',      //  字体颜色
            'fontPath'  =>  TPL_PATH . 'wap/hb_job/OPPOSans-M.ttf',    //  字体路径
            'angle'     =>  0,
        );

        $background     =   $config['background'];//海报最底层得背景

        if (stripos($background, 'http') !== false) {

            //背景方法
            $backgroundInfo =   curlGet($background);
            $background     =   imagecreatefromstring($backgroundInfo);
        } else {

            //背景方法
            $backgroundInfo =   getimagesize($background);
            $backgroundFun  =   'imagecreatefrom'.image_type_to_extension($backgroundInfo[2], false);
            $background     =   $backgroundFun($background);
        }

        $backgroundWidth    =   imagesx($background);    //背景宽度
        $backgroundHeight   =   imagesy($background);   //背景高度

        $imageRes   =   imageCreatetruecolor($backgroundWidth, $backgroundHeight);
        $color      =   imagecolorallocate($imageRes, 255, 255, 255);

        imagefill($imageRes, 0, 0, $color);

        imagecopyresampled($imageRes, $background, 0, 0, 0, 0, imagesx($background), imagesy($background), imagesx($background), imagesy($background));

        //处理了图片
        if (!empty($config['image'])) {
            foreach ($config['image'] as $key => $val) {

                $val    =   array_merge($imageDefault, $val);

                if ($val['stream']) {

                    $info       =   getimagesizefromstring($val['url']);
                    $function   =   'imagecreatefromstring';
                    $res        =   $function($val['url']);
                } else if (stripos($val['url'], 'http') !== false) {

                    $urlInfo    =   curlGet($val['url']);
                    if (!empty($urlInfo)) {
                        $info   =   getimagesizefromstring($urlInfo);
                    }
                    $function   =   'imagecreatefromstring';
                    $res        =   $function($urlInfo);
                } else {

                    $info       =   getimagesize($val['url']);
                    if ($info) {

                        $function   =   'imagecreatefrom'.image_type_to_extension($info[2], false);
                        $res        =   $function($val['url']);
                    }

                }

                // 要判断一下，防止图片不存在，导致报错
                if (!empty($info)) {

                    $resWidth   =   $info[0];
                    $resHeight  =   $info[1];

                    //建立画板 ，缩放图片至指定尺寸
                    $canvas     =   imagecreatetruecolor($val['width'], $val['height']);
                    if(!empty($val['c_opacity'])){
                        $mycolor = imagecolorallocatealpha($canvas, 255, 255, 255, 127); // 为一幅图像分配颜色和透明度。
                        imagecolortransparent($canvas,$mycolor); //3.设置透明色
                        imagefill($canvas,0,0,$mycolor);//4.填充透明色
                    }else{
                        imagefill($canvas, 0, 0, $color);
                    }

                    //关键函数，参数（目标资源，源，目标资源的开始坐标x,y, 源资源的开始坐标x,y,目标资源的宽高w,h,源资源的宽高w,h）
                    imagecopyresampled($canvas, $res, 0, 0, 0, 0, $val['width'], $val['height'], $resWidth, $resHeight);
                    $val['left']=   $val['left'] < 0 ? $backgroundWidth - abs($val['left']) - $val['width'] : $val['left'];
                    $val['top'] =   $val['top'] < 0 ? $backgroundHeight - abs($val['top']) - $val['height'] : $val['top'];

                    //放置图像
                    imagecopymerge($imageRes, $canvas, $val['left'], $val['top'], $val['right'], $val['bottom'], $val['width'], $val['height'], $val['opacity']);//左，上，右，下，宽度，高度，透明度
                }

            }
        }

        //处理文字
        if (!empty($config['text'])) {
            foreach ($config['text'] as $key => $val) {

                $val    =   array_merge($textDefault, $val);
                list($R, $G, $B)    =   explode(',', $val['fontColor']);
                $fontColor          =   imagecolorallocate($imageRes, $R, $G, $B);
                $val['left']        =   $val['left'] < 0 ? $backgroundWidth - abs($val['left']) : $val['left'];
                $val['top']         =   $val['top'] < 0 ? $backgroundHeight - abs($val['top']) : $val['top'];
                imagettftext($imageRes, $val['fontSize'], $val['angle'], $val['left'], $val['top'], $fontColor, $val['fontPath'], $val['text']);
            }
        }

        if (!$config['out']){

            imagejpeg($imageRes);            //在浏览器上显示
            imagedestroy($imageRes);
        }else{

            if (isset($this->config['sy_oss']) && $this->config['sy_oss'] == 1) {

                ob_start();
                imagejpeg($imageRes);
                $img    =   ob_get_contents();
                ob_end_clean();
                $base64 =   base64_encode($img);

                require_once('upload.model.php');
                $uploadM    =   new upload_model($this->db, $this->def);

                $upArr = array(
                    'base' => $base64,
                    'dir' => 'company',
                    'type' => 'logo',
                    'watermark' => 0
                );
                $return =   $uploadM->newUpload($upArr);
                return $return['picurl'];
            }else{
                $dir        =   'data/upload/company/'.date("Ymd");
                $dirname    =   APP_PATH.$dir;
                if(!file_exists($dirname)){
                    mkdir($dirname);
                }
                $imgName    =   '/'.time().'.png';
                $filename   =   $dirname.$imgName;
                imagepng($imageRes, $filename);
                return './'.$dir.$imgName;
            }
        }
    }

}

?>