水印不能在代码点火器中工作

时间:2016-04-20 03:14:24

标签: php codeigniter watermark

我正在尝试使用codeigniter 2x

创建水印图像

这是我在控制器中的代码 gbr.php

$data['watermark']      = base_url('images/watermark.png');
$data['ori']            = base_url('images/ori.jpg');
$this->load->view('file',$data);

我正在使用水手帮手,这是我在 watermark_helper.php 中的代码:

if (!function_exists('watermark')) {
    function watermark($image_original,$watermark) {
        // this tells the browser to render jpg image
        header('content-type: image/jpeg'); 
        // creating png image of watermark
        $watermark = imagecreatefrompng($watermark); 

        // getting dimensions of watermark image
        $watermark_width = imagesx($watermark);  
        $watermark_height = imagesy($watermark);

        // creting jpg from original image
        $image_path = $image_original;
        $image = imagecreatefromjpeg($image_path);  
        // getting the dimensions of original image
        $size = getimagesize($image_path);

        // placing the watermark in the center
        $dest_x = $size[0]/2 - $watermark_width/2;  
        $dest_y = $size[1]/2 - $watermark_height/2;

        imagealphablending($image, true);
        imagealphablending($watermark, true);

        // creating the new image
        imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height); 
        $res = imagejpeg($image); 

        // destroying and freeing memory
        imagedestroy($image);  
        imagedestroy($watermark);

        return $res;

    }
}

这是我的观点:

$this->load->helper('watermark');

<h2>Photo</h2>

<img src="<?=watermark($results[0]['picture'],$watermark);?>" alt="" height="264px" class="img-responsive">enter code here

当我运行我的代码时,图像无法显示,我收到错误...

  

gbr“http://domain.com/inde.php/gbr”tidak bisa di tampilkan karena mengandung kesalahan

2 个答案:

答案 0 :(得分:0)

使用URI更改文件是不可能的(如果不是意图)。 您正在将URL与文件的物理路径混合。 检查这些更改:

代替

$data['watermark']      = base_url('images/watermark.png');
$data['ori']            = base_url('images/ori.jpg');

使用

$data['watermark']      = APPPATH.'images/watermark.png';
$data['ori']            = APPPATH.'images/ori.jpg';

答案 1 :(得分:0)

$config['source_image'] = '/path/to/image/mypic.jpg';
$config['wm_overlay_path'] = '/path/to/wattermark.jpg';
$config['wm_type'] = 'overlay';
$config['wm_vrt_alignment'] = 'top';
$config['wm_hor_alignment'] = 'left';
$config['wm_hor_offset'] = 20; // px
$config['wm_vrt_offset'] = 20; // px
$config['wm_opacity'] = 30; // 1 - 100

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

$this->image_lib->watermark();