在codeigniter

时间:2015-10-09 06:37:37

标签: php codeigniter watermark

我试图在codeigniter上为我的图像添加水印 我可以水印图像,我必须给路径和工作正常,但我想水印我的图像,我要上传,这意味着我选择文件和水印他们并上传到数据库所以我怎么能这样做我的图像上传控制器

控制器

function add_page() {

    $this->access_denied();
    //new page add from form process
    if($this->input->post('add')) {

      $this->form_validation->set_rules('slug', 'slug', 'trim|required|min_length[4]|max_length[200]');
      $this->form_validation->set_rules('title', 'title', 'trim|required');
      $this->form_validation->set_rules('details', 'details', 'trim|required');
      if ($this->form_validation->run()) {

        $slug = strip_tags(url_title($this->input->post('slug')));
        $title = $this->input->post('title');
        $details = $this->input->post('details');
        $publish_date = time();
        $added_by = $this->session->userdata('full_name');


        // if image is uploaded
        if (isset($_FILES['userfile']['name']) && $_FILES['userfile']['size']>0) {

          $config = array('upload_path' => './uploads/page/',
                          'allowed_types' => 'jpg|gif|png|jpeg|ico',
                          'max_size' => 0,
                          'max_height' => 0,
                          'max_width' =>0
                        );
          $this->load->library('upload', $config);

          if ($this->upload->do_upload()) {
            $image_files = $this->upload->data();z
            $this->page_model->add_page($slug, $title, $details, $image_files['file_name'], $publish_date, $added_by);
            $this->session->set_flashdata('error_msg', '<div class="alert alert-success" role="alert") New page has been added successfully.</div>');
            redirect('page/manage-page');
          }
          else {
            $this->session->set_flashdata('error_msg', $this->upload->display_errors());
            redirect('page/add_page');
          }

        }
        else {
          $this->page_model->add_page($slug, $title, $details, null,$publish_date,$added_by);
          $this->session->set_flashdata('error_msg', '<div class="alert alert-success" role="alert") New page has been added successfully.</div>');
          redirect('page/manage-page');
        }
      }


    }
    $data = array('page_title' => "Add new page",
                  'keywords' =>"",
                  'description' => "",
                  'image' => "",
                  'url'=> "",
                  'author' => "",
                  'page_content' => $this->load->view('page/add', '', true)
                );
    $this->load->view('dashboard', $data);
  }

我希望它不会吓到你们,但对我来说这将是非常有帮助的。

3 个答案:

答案 0 :(得分:0)

您可以在PHP中使用库WideImage。它具有用于添加水印的预定义功能。 link

答案 1 :(得分:0)

您可以使用codeigniter进行水印link

$config['source_image'] = '/path/to/image/mypic.jpg';
$config['wm_text'] = 'Copyright 2006 - John Doe';
$config['wm_type'] = 'text';
$config['wm_font_path'] = './system/fonts/texb.ttf';
$config['wm_font_size'] = '16';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '20';

$this->image_lib->initialize($config);

$this->image_lib->watermark();

答案 2 :(得分:0)

这是一个很好的代码,可以帮助您进行图像上传和水印

图片上传水印

http://demo.codesamplez.com/codeigniter/image-demo