CI。 PHP。动态文本水印返回白色框,没有图像

时间:2016-01-26 17:27:58

标签: php image codeigniter watermark

我正在尝试使用某些文本为png或jpg图像添加水印。我正在使用Codeigniter image_lib,但我也尝试过只使用PHP。当它不是动态的时候它适用于这两种情况,但是如果启用了动态选项,那么它就不起作用。 在这里我的尝试:

使用PHP:

    $imgpath='../assets/uploads/11/';
    $filename = $_REQUEST['filename'];
    $im = imagecreatefrompng($imgpath.$filename);
    //figure out where to put the text
    $x_offset = 7;
    $y_offset = 7;  
    $textcolor = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
    imagestring($im, 5, $x_offset, $y_offset, 'watermark text goes here', $textcolor);
    //output watermarked image
    header('Content-type: image/png');
    imagejpeg($im);

使用Codeigniter image_lib:

function watermark_image() 
{
    $this->load->library('image_lib');
    $imgpath='../assets/uploads/11/';
    $filename = $_REQUEST['filename'];
    //Put them all together to get the full path to the image:
    $config['source_image']     = $imgpath.$filename; 
    $config['wm_text']          = date(now());
    $config['wm_type']          = 'text';
    $config['wm_font_path']     = './fonts/arial-webfont.ttf';
    $config['wm_font_size']     = 16;
    $config['wm_font_color']    = 'ffffff';
    $config['wm_vrt_alignment'] = 'middle';
    $config['wm_hor_alignment'] = 'center';
    $config['wm_padding']       = '20';
    $config['dynamic_output']   = TRUE;
    $this->image_lib->initialize($config);

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

}

但它只输出一个白框: Box displayed.

0 个答案:

没有答案