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

时间:2014-05-29 09:43:29

标签: php codeigniter image-processing watermark

我试图将图像放在另一个图像(水印)上,如下所示:     

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);
    }

}

但我一直收到错误:

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

我错过了什么?

1 个答案:

答案 0 :(得分:3)

这个问题很简单,只需删除正斜杠(尽管在documentation example正斜杠存在),就像这样:

$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';
是什么让我混淆了这个错误:

  

您的服务器不支持处理此功能所需的GD功能   图像类型。

当我看到上面的错误时,我从未想过它只是一个路径问题。