這是我一直在嘗試做的事情,但它總是顯示破碎的圖像。我甚至啓用了錯誤報告,但一切似乎返回罰款..只是圖像不顯示。從你的腳本:(PHP和GD破損的圖像
http://www.tradenepal.com.np/test.php
<?php
//Report all Errors
ini_set("display_errors", "1");
error_reporting(E_ALL);
//Set content type
header('content-type: image/jpeg');
//Store the values of our date in separate variables
list($month, $day, $year) = explode('/', date('F/jS/Y'));
//Load our base image
$image = imagecreatefrompng('calendar_blank.png');
$image_width = imagesx($image);
//Setup colors and font file
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$font_path = 'advent_light';
//Get the positions of the text string
$pos_month = imagettfbbox(13, 0, $font_path, $month);
$pos_day = imagettfbbox(25, 0, $font_path, $day);
$pos_year = imagettfbbox(8, 0, $font_path, $year);
//Create Month
imagettftext($image, 13, 0, ($image_width - $pos_month[2])/2, 40, $white, $font_path, $month);
//Create Day
imagettftext($image, 25, 0, ($image_width - $pos_day[2])/2, 80, $black, $font_path, $day);
//Create Year
imagettftext($image, 8, 0, ($image_width - $pos_year[2])/2, 100, $black, $font_path, $year);
//Create final image
imagejpeg($image, '', 100);
//Clear up memory;
imagedestroy($image);
?>
首先註釋'header('content-type:image/jpeg')',如果有任何錯誤,請參閱錯誤,因爲頭部是用於圖像,所以您看不到它們。 – tradyblix
我覺得問題出在你的'$ font_path ='advent_light';'這是一個無效的字體文件名 – ASR
@Bob,也許他使用自定義字體或者只是重命名了一個。 – Wh1T3h4Ck5