简体   繁体   中英

watermark and upload image on codeigniter

im trying to watermark my image on codeigniter i can watermark image which i have to gave path and that works fine but i want to watermark my image which im going to upload that means i choose files and watermark them and upload it to database so how can i do that here is my image uploading controller

Controller

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);
  }

i hope it wont freak you out guys but it would be great help for me thanks.

You may use the library WideImage in PHP. It has the predefined functions for adding the watermarks. link

You can use codeigniter for Watermarking 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();

Here is the good code which will help you for the image upload and watermarking

Image Upload and Watermarking

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM