codeigniter image watermark script code example
Example: upload image with watermark in codeigniter
$wm_font_size = 16;
$this->load->library('upload');
$this->load->library('image_lib');
$config['image_library'] = 'GD2';
for ($i = 0; $i < $number_of_files; $i++) {
$_FILES['file']['name'] = $files['file']['name'][$i];
$_FILES['file']['type'] = $files['file']['type'][$i];
$_FILES['file']['tmp_name'] = $files['file']['tmp_name'][$i];
$_FILES['file']['error'] = $files['file']['error'][$i];
$_FILES['file']['size'] = $files['file']['size'][$i];
$config['source_image'] = $files['file']['tmp_name'][$i];
$config['wm_text'] = 'Copyright example.com';
$config['wm_type'] = 'text';
$config['wm_font_size'] = ceil($files['file'][image_height][$i]/100*wm_font_size);
$config['wm_vrt_alignment'] = 'middle';
$config['wm_hor_alignment'] = 'center';
$this->image_lib->initialize($config);
$this->image_lib->watermark();
$config['source_image'] = $files['file']['tmp_name'][$i];
$config['wm_overlay_path'] = './application/assets/images/example.png';
$config['wm_type'] = 'overlay';
$config['width'] = '50';
$config['height'] = '50';
$config['padding'] = '50';
$config['wm_opacity'] = '100';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'right';
$config['wm_vrt_offset'] = '100';
$this->image_lib->initialize($config);
$this->image_lib->watermark();
if (!$this->upload->do_upload("file")) {
$errors++;
}