Internal/Image这个插件很坑,如果不设置字体的话,无法调整文字的大小,这个错误是因为你的字体文件路径不对所导致的!
解决方法:
1.把字体文件,放在public文件夹下的fonts文件夹
2.在服务器的话,使用绝对路径也可以,不过在本地调试的话不能使用绝对路径,要用相对地址
public function createCertification(){
// create Image from file
$img = Image::make("你的图片地址")->resize(1200,800);
$str = "大美女";
$number = "1001";
$img->text($str, 350, 260, function($font) {
$font->file("./fonts/hwzs.ttf"); //这才是正确的文件路径使用方式,在服务器的话,使用绝对路径也可以,不过在本地调试的话不能使用绝对路径
$font->size(40);
});
$img->text('ABCDEFG'.$number, 290, 320, function($font) {
$font->file("./fonts/hwzs.ttf");
$font->size(35);
});
ob_end_clean(); //这步很关键,不用的话会输出乱码
// send HTTP header and output image data
return $img->response();
}