duanrong5167 2014-05-29 09:43
浏览 94
已采纳

如何在Codeigniter中创建图像水印wm_type overlay?

I am trying to put an image over another image (watermark) like so:

class Water_mark extends CI_Controller {

    function __construct() {
        parent::__construct();
    }

    function index() {
        $this->load->library('image_lib');
        $config['image_library'] = 'GD2';
        $config['source_image'] = '/assets/images/tv-share.jpg';
        $config['new_image'] = '/assets/images/tv-share-done.jpg';
        $config['wm_type'] = 'overlay';
        $config['wm_overlay_path'] = '/assets/images/share_en.jpg';
        $config['wm_opacity'] = '50';
        $config['wm_vrt_alignment'] = 'top'; 
        $config['wm_hor_alignment'] = 'left';
        $config['wm_hor_offset'] = '10';
        $config['wm_vrt_offset'] = '10';

        $data = $config;
        $this->image_lib->initialize($config);

        if (!$this->image_lib->watermark()) {
            echo $this->image_lib->display_errors();
        }
        $this->image_lib->clear();

        $this->load->view('water_mark_view', $data);
    }

}

but I keep getting errors:

A PHP Error was encountered
Severity: Warning
Message: imagecolorat() expects parameter 1 to be resource, boolean given
Filename: libraries/Image_lib.php
Line Number: 941
A PHP Error was encountered
Severity: Warning
Message: imagecolorat() expects parameter 1 to be resource, boolean given
Filename: libraries/Image_lib.php
Line Number: 953
A PHP Error was encountered
Severity: Warning
Message: imagecolortransparent() expects parameter 1 to be resource, boolean given
Filename: libraries/Image_lib.php
Line Number: 953
A PHP Error was encountered
Severity: Warning
Message: imagecopymerge() expects parameter 1 to be resource, boolean given
Filename: libraries/Image_lib.php
Line Number: 954
The path to the image is not correct.
The path to the image is not correct.
The path to the image is not correct.
Your server does not support the GD function required to process this type of image.
Your server does not support the GD function required to process this type of image.
Your server does not support the GD function required to process this type of image.

GD phpinfo

What am I missing?

  • 写回答

1条回答 默认 最新

  • duan19780629 2014-05-29 10:31
    关注

    The issue was as simple as removing the forward slash (although in the documentation example the forward slash exists) at he beginning like so:

    $config['source_image'] = 'assets/images/tv-share.jpg';
    $config['new_image'] = 'assets/images/tv-share-done.jpg';
    $config['wm_overlay_path'] = 'assets/images/share_en.jpg';
    

    what got me confused this error:

    Your server does not support the GD function required to process this type of image.

    I never thought it was only a path issue when I saw the error above.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊