问题描述
我正在使用CI上传库上传图像,但工作正常,存在水印和图像缩略图的问题,如果id先对水印进行水印,然后再对缩略图进行水印,则对原始图像进行水印处理,但还要调整其缩略图大小,但不能保持原始大小带有水印的图像也是如此,如果我先做缩略图,然后水印就可以了,但是我也想给水印加缩略图,这是我的代码
i am uploading an image using CI upload library work fine, problem with watermarking and image thumbnail, if id do watermarking first and then thumbnail, its doing watermarking to original image but also re-sized it thumbnail size but not keeping original size image with watermark too, if i do thumbnail first then watermark it work fine but i want thumbnail also watermarked here is my code
$this->do_thumb('file_name');
$this->watermark('file_name');
function watermark($filename){
$image_cfg = array();
$image_cfg['image_library'] = 'GD2';
$image_cfg['source_image'] = 'upload/' . $filename;
$image_cfg['wm_overlay_path'] = 'upload/watermark.png';
$image_cfg['new_image'] = 'upload/mark_'.$filename;
$image_cfg['wm_type'] = 'overlay';
$image_cfg['wm_opacity'] = '10';
$image_cfg['wm_vrt_alignment'] = 'bottom';
$image_cfg['wm_hor_alignment'] = 'right';
$image_cfg['create_thumb'] = FALSE;
$this->image_lib->initialize($image_cfg);
$this->image_lib->watermark();
$this->image_lib->clear();
// echo $this->image_lib->display_errors();
// die();
}
function do_thumb($filename) {
$image_cfg['image_library'] = 'GD2';
$image_cfg['source_image'] = 'upload/' . $filename;
$image_cfg['create_thumb'] = TRUE;
$image_cfg['maintain_ratio'] = TRUE;
$image_cfg['width'] = '200';
$image_cfg['height'] = '175';
$this->load->library('image_lib');
$this->image_lib->initialize($image_cfg);
$this->image_lib->resize();
$this->image_lib->clear();
}
推荐答案
执行 watermark()
,然后 do_thumb()
,删除 $ image_cfg ['new_image']
使用水印功能或如果要使用它,请将 $ image_cfg ['new_image']
值传递给 do_thumb()
。
Execute watermark()
first, then do_thumb()
, remove $image_cfg['new_image']
at watermark function or if you want to use it, pass $image_cfg['new_image']
value to do_thumb()
.
也不要忘记将 $ image_cfg ['new_image']
设置为 do_thumb()
因此它会创建新的拇指文件而不是重写
Also dont forget to set $image_cfg['new_image']
at do_thumb()
so it create new thumb file not rewrite it
为什么拇指不包含水印的问题是因为您使用原始图像而不是给图像加水印作为拇指的图像源。希望你明白我的意思,因为英语不是我的母语,php是..
The problem why your thumb not contain watermark is because you use original image not the watermarking image as the image source for the thumb. hope you understand what i mean cos english is not my first language, php it is ..
这篇关于Codeigniter图片上传水印和缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!