我正在使用imagejpg()在浏览器上显示图像并将文本放在图像上。
之前我已经使用过这个功能了。现在我切换了域名主机,也许PHP版本不同,因为图像现在没有显示。
它在屏幕中间显示一个小方块,就像一个断开的链接,但图像肯定在那里。
有人可以帮忙吗?
header('Content-type: image/jpeg');
// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('images1/new_image.jpg');
// Allocate A Color For The Text
$red = imagecolorallocate($jpg_image, 255, 0, 0);
$green = imagecolorallocate($jpg_image, 0, 255, 0);
// Set Path to Font File
$font_path = 'canadian.ttf';
$text1 = "hello";
$text2 = "there";
$text3 = "world";
//Floor 17
imagettftext($jpg_image, 12, 0, 272, 17, $green, $font_path, $text1);
imagettftext($jpg_image, 12, 0, 200, 38, $green, $font_path, $text2);
imagettftext($jpg_image, 12, 0, 480, 17, $green, $font_path, $text3);
// Send Image to Browser
imagejpeg($jpg_image);
// Clear Memory
imagedestroy($jpg_image);
提前谢谢。
罗布
答案 0 :(得分:1)
我只是想通了。答案如下
我向下移动了标题,它解决了问题。
// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('images1/new_image.jpg');
// Allocate A Color For The Text
$red = imagecolorallocate($jpg_image, 255, 0, 0);
$green = imagecolorallocate($jpg_image, 0, 255, 0);
// Set Path to Font File
$font_path = 'canadian.ttf';
$text1 = "hello";
$text2 = "there";
$text3 = "world";
//Floor 17
imagettftext($jpg_image, 12, 0, 272, 17, $green, $font_path, $text1);
imagettftext($jpg_image, 12, 0, 200, 38, $green, $font_path, $text2);
imagettftext($jpg_image, 12, 0, 480, 17, $green, $font_path, $text3);
header('Content-type: image/jpeg');
// Send Image to Browser
imagejpeg($jpg_image);
// Clear Memory
imagedestroy($jpg_image);
答案 1 :(得分:0)
我遇到了同样的问题,发现如果标题前有一个空格,则该图像将不起作用。 我能够将图像保存在服务器上,但无法让浏览器显示它。 删除每个空白对我来说都是成功的窍门。 我认为这是您的脚本在开始时无法与标头一起使用的原因。