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 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳