用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2716|回复: 2
收起左侧

[HELP] 给图片打水印(高手请进)

[复制链接]
发表于 2011-7-21 09:35:32 | 显示全部楼层 |阅读模式
class Propic extends Backdata_controller{
        var $rule_post=array(
                array(
                        'field'=>'title',
                        'rules'=>'trim'),
                array(
                        'field'=>'show',
                'rules'=>'intval'),
                );
       
        function on_load(){
                $this->backauth->can_access_menu(100086);
                $this->view=$this->table=strtolower(get_class($this));
        }
       
        function on_index(){
                $this->load->database();
                $this->db->select('title');
                $parent_rs=$this->db->get_where('project'
                        ,array('id'=>$this->uri->segment(3,-1)),1);
                $this->load->vars(array(
                        'parent_rs'=>$parent_rs->row(),
                        ));
                return array('type_column'=>'book_id');
        }
       
        function post(){
                $backward='create';
                $link_method='index';
               
                $type_id=$book_id=$this->uri->segment(3,-1);
               
                $this->load->library('form_validation',$this->rule_post);
                if(!$this->form_validation->run()){
                        return $this->$backward();
                }
                $form=$this->form_validation->to_array();
                $form['show']=1;
                $form['book_id']=$book_id;
                $form['timeline']=time();
               
                //batch upload
                $b=$this->input->post('upload_clear');
                if(is_array($b)){
                        $this->load->helper('upload_clear');
                        foreach($b as $v){//make sure photo and thumb cleared together
                                if(strpos($v,'_thumb.')){
                                        $v=str_replace('_thumb.','.',$v);
                                        if(!in_array($v,$b)){
                                                $b[]=$v;
                                        }
                                }
                        }
                        upload_clear($b);
                }
                $a=$this->input->post('userfile_list');
                if(is_array($a)&&count($a)>0){
                        $photo=$thumb=array();
                        foreach($a as $v){
                                $k=$this->model->_url_to_path($v);
                                if(empty($k)||!is_file($k)){
                                        continue;
                                }
                                if(strpos($v,'_thumb')){
                                        $thumb[str_replace('_thumb','',$v)]=$v;
                                }else{
                                        $photo[$v]=1;
                                }
                        }
                        foreach($photo as $pic=>$k){
                                $tmb=(isset($thumb[$pic])?$thumb[$pic]pic);
                                $form['photo']=$pic;
                                $form['thumb']=$tmb;
                                $this->model->post($form);
                        }
                }
               
                $this->backview->success($this->lang->line('item_post_success')
                        ,array('继续添加'=>"ajax:{$this->title}/create/$type_id"
                                ,'完成'=>"{$this->title}/$link_method/$type_id"));
        }
       
        function on_put(){
                return array('rule'=>$this->rule_post);
        }
       
        function on_toggle(){
                return array(
                        'id_segment'=>4,
                        'column_segment'=>5
                );
        }
       
        function on_insert(&$form){
                if(empty($form['photo']))return;
                $photo=$this->_url_to_path($form['photo']);
                if(!file_exists($photo))return;
                $this->load->library('image_lib');
                $config=array();
                $config['source_image'] = $photo;
                $config['wm_type'] = 'overlay';
                $config['wm_vrt_alignment'] = 'top';
                $config['wm_hor_alignment'] = 'left';
                $config['wm_padding'] = '10';
                $config['wm_overlay_path'] = base_url().'shuiyin.png';
                echo $config['wm_overlay_path'];exit;
                $this->image_lib->initialize($config);
                $this->image_lib->watermark();
        }
       
        function on_update(&$form){
                if(empty($form['photo']))return;
                $photo=$this->_url_to_path($form['photo']);
                if(!file_exists($photo))return;
                $this->load->library('image_lib');
                $config=array();
                $config['source_image'] = $photo;
                $config['wm_type'] = 'overlay';
                $config['wm_vrt_alignment'] = 'top';
                $config['wm_hor_alignment'] = 'left';
                $config['wm_padding'] = '0';
                $config['wm_overlay_path'] = base_url().'shuiying.png';
                //echo $config['wm_overlay_path'];exit;
               
                $this->image_lib->initialize($config);
                $this->image_lib->watermark();
        }
       
        function _url_to_path($url){
                $upurl=rtrim(config_item('upload.url'),'/\\').'/';
                $updir=rtrim(config_item('upload.dir'),'/\\').'/';
                if(empty($url)||is_int($url)){
                        return '';
                }
                if(!strncasecmp($url,$upurl,strlen($upurl))){
                        $url=$updir.substr($url,strlen($upurl));
                }
                return $url;
        }
}

没效果求解!修改别人的代码
发表于 2011-7-27 10:34:30 | 显示全部楼层
好东西,收藏
发表于 2011-7-27 12:34:45 | 显示全部楼层
这不是我的代码吗,去bom了没?

本版积分规则