在codeigniter代码中给文本作为图片上的水印无法正常运行。
public function new()
{
$this->load->library('image_lib');
$config['sourse_image'] ='./SaveImage/fer.jpg';
$config['wm_text'] = 'SaleScrap';
$config['wm_type'] = 'text';
$config['wm_font_path'] = 'system/fonts/texb.ttf';
$config['wm_font_size'] = '16';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '20';
$this->image_lib->initialize($config);
if($this->image_lib->watermark())
{
echo "Success";
}
else
{
echo "Error";
}
}
代码不起作用,并且当代码运行时日志文件给出此错误
,无法给出输出ERROR - 2018-08-29 11:49:54 --> You must specify a source image in your preferences.
ERROR - 2018-08-29 11:49:54 --> Your server does not support the GD function required to process this type of image.
答案 0 :(得分:0)
解决方案1
$config['sourse_image'] ='./SaveImage/fer.jpg';
source_image的正确拼写
解决方案2。
您应该尝试使用以下结构:
$this->load->library('image_lib');
// Set your config up
$this->image_lib->initialize($config);
// Do your manipulation
$this->image_lib->clear();
如果没有任何效果,则错误可能实际上是整个问题。 检查是否已安装gd,在Linux上会做
sudo yum list installed | grep php
如果未安装,请安装
sudo yum install php-gd-package-name
重新启动您的Apache
sudo服务httpd重新启动