[英]PHP imagejpeg not displaying image on Browser
我正在使用 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);
先感謝您。
搶
我只是想通了。 下面回答
我將標題向下移動並解決了問題。
// 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);
我遇到了同樣的問題,發現如果標題前有空格,則圖像不起作用。 我能夠將圖像保存在服務器上,但無法讓瀏覽器顯示它。 刪除每一個空格對我來說都是成功的。 我認為這與您的腳本在開始時無法與標題一起使用的原因相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.