[英]watermark not working in code igniter
I'm trying to make watermark image with codeigniter 2x 我正在尝试使用Codeigniter 2x制作水印图像
This is my code in controller gbr.php : 这是我在控制器gbr.php中的代码:
$data['watermark'] = base_url('images/watermark.png');
$data['ori'] = base_url('images/ori.jpg');
$this->load->view('file',$data);
I'm using helper for watermark and this is my code in watermark_helper.php : 我正在使用帮助程序进行水印,这是我在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 is my view: 这是我的看法:
$this->load->helper('watermark');
<h2>Photo</h2>
<img src="<?=watermark($results[0]['picture'],$watermark);?>" alt="" height="264px" class="img-responsive">enter code here
when I run my code, the image can not display and I get the error... 当我运行代码时,图像无法显示,并且出现错误...
gbr " http://domain.com/inde.php/gbr " tidak bisa di tampilkan karena mengandung kesalahan
gbr“ http://domain.com/inde.php/gbr ” tidak bisa di tampilkan karena mengandung kesalahan
It is not possible (if not intended) to change files with URI. 无法(如果不打算)使用URI更改文件。 You are mixing URL with physical path of a file.
您正在将URL与文件的物理路径混合在一起。 Check these changes:
检查以下更改:
instead 代替
$data['watermark'] = base_url('images/watermark.png');
$data['ori'] = base_url('images/ori.jpg');
use 采用
$data['watermark'] = APPPATH.'images/watermark.png';
$data['ori'] = APPPATH.'images/ori.jpg';
$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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.