在使用imagettftext函数时,通常会使用相对路径作为字体文件路径,但在vscode编写时,会报文件无法找到问题,并不是文件路径有错,而是在vscode中,这个函数的路径不支持相对路径。可用两种方案解决:
方案1:绝对路径
$ttfFile = realpath(".'E:\phpTest\php01\jadesmile.ttf'");
imagettftext($img, 30, -10, 0, 30, $colorText,$ttfFile , "abcd");
方案2:相对路径转为绝对路径
$ttfFile = realpath("./jadesmile.ttf");
imagettftext($img, 30, -10, 0, 30, $colorText, $ttfFile, "abcd");