我有一个辅助功能,可以为图像添加水印
(我做了一些更改以缩短代码,请忽略轻微的语法错误或遗漏代码)
function watermark($path_to_img , $image_name )
{
$ci = &get_instance();
$config['source_image'] = $path_to_img.$image_name;;
$config['new_image'] = $path_to_img.'wtr_'.$image_name;
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = base_path('/files/transparent_bar.png');
$config['wm_font_path'] = base_path('application/assets/view/tahomabd.ttf');
$config['wm_font_size'] = '8';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'left';
$config['quality'] = '100%';
$config['wm_hor_offset'] = '0';
$config['wm_vrt_offset'] = '0';
$ci->image_lib->initialize($config);
$ci->image_lib->watermark();
}
它运行正常,但它将水印版本保存在服务器上,我想在运行时显示/下载它而不保存在服务器上或替换原始图像....我不知道我怎么能这样做在codeigniter?
类似的东西:
$img = watermark($path_to_img , $image_name);
header("Content-type: image/jpeg");
echo ( $img );
答案 0 :(得分:1)
您仍然可以将其保存在临时目录中,并使用代码删除超过几分钟的图像。或者更难,有一个PHP脚本流出图像,例如URL应该类似于script.php?IMG = flower.jpg
答案 1 :(得分:0)
要替换源图像,请将源图像路径设置为新图像。
$config['source_image'] = $path_to_img.$image_name;
$config['new_image'] = $path_to_img.$image_name;