欢迎各位兄弟 发布技术文章
这里的技术是共享的
require_once 'vendor/autoload.php'; use Intervention\Image\ImageManagerStatic as Image; $img = Image::make($_GET['backgroundsPath'].$_GET['backgroundFile']); $img->text($_GET['text'], 335, 175, function ($font) { $font->file('../fonts/intro-black-caps-webfont.woff'); $font->size(34); $font->color("#ffffff"); $font->align('center'); $font->valign('top'); });
来自 https://github.com/Intervention/image/issues/495
//文字水印
if($curr_category->category_is_watermark==1){
$middle_position_x = $img->width()/2; //这是原图像的一半的宽度
$end_position_x = $img->width(); //这是原图像的宽度
$middle_position_y = $img->height()/2; //这是原图像的一半的高度
$end_position_y = $img->height();//这是原图像的高度
if($curr_category->category_watermark_position=='watermark_position_left_top'){
$position_x = 5;
$position_y = 5;
$position_align = 'left';
$position_valign = 'top';//左上角
}
else if($curr_category->category_watermark_position=='watermark_position_middle_top'){
$position_x = $middle_position_x;
$position_y = 5;
$position_align = 'center';
$position_valign = 'top';//中上角
}
else if($curr_category->category_watermark_position=='watermark_position_right_top'){
$position_x = $end_position_x-5;
$position_y = 5;
$position_align = 'right';
$position_valign = 'top';//右上角
}
else if($curr_category->category_watermark_position=='watermark_position_right_middle'){
$position_x = $end_position_x-5;
$position_y = $middle_position_y;
$position_align = 'right';
$position_valign = 'top';//右中角
}
else if($curr_category->category_watermark_position=='watermark_position_right_bottom'){
$position_x = $end_position_x-5;
$position_y = $end_position_y-5;
$position_align = 'right';
$position_valign = 'bottom';//右下角
}
else if($curr_category->category_watermark_position=='watermark_position_middle_bottom'){
$position_x = $middle_position_x;
$position_y = $end_position_y-5;
$position_align = 'center';
$position_valign = 'bottom';//中下角
}
else if($curr_category->category_watermark_position=='watermark_position_left_bottom'){
$position_x = 5;
$position_y = $end_position_y-5;
$position_align = 'left';
$position_valign = 'bottom';//左下角
}
else if($curr_category->category_watermark_position=='watermark_position_left_middle'){
$position_x = 5;
$position_y = $middle_position_y;
$position_align = 'left';
$position_valign = 'top';//左中角
}
else if($curr_category->category_watermark_position=='watermark_position_middle'){
$position_x = $middle_position_x;
$position_y = $middle_position_y;
$position_align = 'center';
$position_valign = 'top';//中间
}
$img->text($curr_category->category_watermark_word, $position_x, $position_y, function($font) use($position_align,$position_valign){
$font->file(public_path('assets/front/watermark/font/msyh.ttf'));
$font->size(18);
$font->color('#ff0000');
$font->align($position_align);
$font->valign($position_valign);
//$font->angle(45);
});
}