这是我一直在尝试做的事情,但它总是显示破碎的图像。我甚至启用了错误报告,但一切似乎返回罚款..只是图像不显示。从你的脚本:(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