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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵