upload image with watermark in codeigniter

Solutions on MaxInterview for upload image with watermark in codeigniter by the best coders in the world

showing results for - "upload image with watermark in codeigniter"
Caterina
20 Sep 2017
1        // Define it in configuration file. And call it
2        // About configurations: https://codeigniter.com/user_guide/libraries/config.html
3        $wm_font_size = 16; // Watermark height (font size) contains 16% of image 
4
5        $this->load->library('upload');
6        $this->load->library('image_lib');
7        $config['image_library'] = 'GD2';
8
9        for ($i = 0; $i < $number_of_files; $i++) {
10                $_FILES['file']['name'] = $files['file']['name'][$i];
11                $_FILES['file']['type'] = $files['file']['type'][$i];
12                $_FILES['file']['tmp_name'] = $files['file']['tmp_name'][$i];
13                $_FILES['file']['error'] = $files['file']['error'][$i];
14                $_FILES['file']['size'] = $files['file']['size'][$i];
15                $config['source_image'] = $files['file']['tmp_name'][$i];
16                $config['wm_text'] = 'Copyright example.com';
17                $config['wm_type'] = 'text';
18                $config['wm_font_size'] = ceil($files['file'][image_height][$i]/100*wm_font_size);
19                $config['wm_vrt_alignment'] = 'middle';
20                $config['wm_hor_alignment'] = 'center';
21                $this->image_lib->initialize($config);
22                $this->image_lib->watermark();
23
24                $config['source_image'] = $files['file']['tmp_name'][$i];
25                $config['wm_overlay_path'] = './application/assets/images/example.png';
26                $config['wm_type'] = 'overlay';
27                $config['width'] = '50';
28                $config['height'] = '50';
29                $config['padding'] = '50';
30                $config['wm_opacity'] = '100';
31                $config['wm_vrt_alignment'] = 'bottom';
32                $config['wm_hor_alignment'] = 'right';
33                $config['wm_vrt_offset'] = '100';
34                $this->image_lib->initialize($config);
35                $this->image_lib->watermark();
36
37                if (!$this->upload->do_upload("file")) {
38                    $errors++;
39                }