|
Opencart 增加浮水印需要修改三个个文件,
opencart\catalog\model\tool\image.php
opencart\admin\model\tool\image.php
找到这两个文件,大约27行 , 找到这行代码
$image = new Image(DIR_IMAGE . $old_image);
在这行后面加入一行
$image->imagefttext();
然后找到
opencart\system\library\image.php
在
public function resize($width = 0, $height = 0) { 的上面加入下面的内容
public function imagefttext($position = 'bottomright'){
//$white = imagecolorallocate($this->image, 255, 255, 255);
$grey = imagecolorallocate($this->image, 128, 128, 128);
//$black = imagecolorallocate($this->image, 0, 0, 0);
//水印的文字
$text = 'KingPlesk.org';
//字体文件请放在IMAGE的文件夹下
$font = DIR_IMAGE.'ARIAL.TTF';
$font_size = 20;
$len = $this->info['width']/3;
switch($position) {
case 'topleft':
$watermark_pos_x = 0;
$watermark_pos_y = 0;
break;
case 'topright':
$watermark_pos_x = $this->info['width'] - $len;
$watermark_pos_y = 0;
break;
case 'bottomleft':
$watermark_pos_x = 0;
$watermark_pos_y = $this->info['height'] - $len;
break;
case 'bottomright':
$watermark_pos_x = $this->info['width'] - $len;
$watermark_pos_y = $this->info['height'] - $font_size;
break;
case 'center':
$watermark_pos_x = $this->info['width']/2-20;
$watermark_pos_y = $this->info['height']/2-20;
break;
}
imagettftext($this->image, $font_size, 0, $watermark_pos_x, $watermark_pos_y, $grey, $font, $text);
}
public function imagefttext($position = ‘bottomright’){ 这个函数有一个参数
topleft 左上
topright 右上
bottomleft 左下
bottomright 右下
浮水印的位置,在image.php 的
$image->imagefttext();
可以这样调用
$image->imagefttext(‘topleft’);
浮水印效果
转帖:https://kingplesk.org/archives/239#codesyntax_1 |
|