ci图像处理库,给图片加加水印和缩略图出错
我想实现的功能是,可以单独只给源图片弄个缩略图,还可以单独的给源文件加水印,但是还要有一个没有处理过的源文件。问题:单独只加水印和只能缩略图没有问题,但是两个弄的时候就出错了,上传的文件夹中会生成四个图片
分别是:**.jpg(源文件),**_thumb.jpg,**_mark.jpg,**_mark_thumb.jpg(不懂这个是怎么冒出来的)
<?php
class Deal_picture extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->database();
$this->load->library('upload');
$this->load->library('image_lib');
$this->load->helper('form');
}
public function index()
{
}
public function add()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['file_name']=time();
$config['max_size'] = '100';
$config['max_width']= '1000';
$config['max_height']= '1000';
$this->upload->initialize($config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
print_r($error);
}
else
{
header("Content-type:text/html;charset=utf-8");
$file_info = $this->upload->data();
if(isset($_POST['hasThumb'])) //只是缩略图
{
$this->has_thumb($file_info); //缩略图函数
}
if(isset($_POST['hasMark']))
{
$new_file='./uploads/'.$file_info['raw_name'].'_mark'.$file_info['file_ext'];
copy('./uploads/'.$file_info['file_name'], $new_file); //因为ci图像类库加水印不像变缩略图一样可以可以直接备份,所 以我在这里备份
$this->has_mark($new_file); //加水印函数
}
}
}
//缩略图
public function has_thumb($file)
{
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/'.$file['file_name'];
$config['new_image']='./uploads/'; //有这个参数可以为原来的文件自动备份一个
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->image_lib->initialize($config);
$this->image_lib->resize();
}
//加水印
public function has_mark($img)
{
$config['source_image'] = $img;
$config['wm_text'] = 'rainbow';
$config['wm_type'] = 'text';
$config['wm_font_path'] = './system/fonts/texb.ttf';
$config['wm_font_size'] = '20';
$config['wm_font_color'] = '000000';
$config['wm_vrt_alignment'] = 'middle';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '20';
$this->image_lib->initialize($config);
$this->image_lib->watermark();
}
}
:lol 你好。请问你这个问题解决了吗?我也遇到了这个问题,CI框架,不能生成缩略图后,再拿原图去加水印吗? 沛先森 发表于 2017-2-22 10:00
你好。请问你这个问题解决了吗?我也遇到了这个问题,CI框架,不能生成缩略图后,再拿原图去加水印吗 ...
具体贴一下代码看看,这个帖子是12年的,4年前的老帖了。 解决了,就水印函数加$config['thumb_marker'] = '_water';
就不会跟缩略图冲突了
create_thumb FALSE TRUE/FALSE (boolean) 告诉图像处理函数生成缩略图。 R
看手册的时候,被这个R,
"可用性" 符号说明:
R - 调整图像大小
C - 图像裁剪
X - 图像旋转
W - 添加图像水印
页:
[1]