2012-09-11 51 views
1

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

首先注释'header('content-type:image/jpeg')',如果有任何错误,请参阅错误,因为头部是用于图像,所以您看不到它们。 – tradyblix

+0

我觉得问题出在你的'$ font_path ='advent_light';'这是一个无效的字体文件名 – ASR

+0

@Bob,也许他使用自定义字体或者只是重命名了一个。 – Wh1T3h4Ck5

回答

1

输出如下。你可以看到这个自己,如果您删除内容类型标题,或使用工具,如提琴手。另外,这些“免费的网络在那里举办”行,你将永远不会得到这个工作。



PHP错误信息
Warni NG:imagecreatefrompng(calendar_blank.png)[function.imagecreatefrompng]:未能打开流:在/home/a5838755/public_html/test.php没有这样的文件或目录上线

免费虚拟主机
PHP错误信息
警告:imagesx():提供的参数不是在/home/a5838755/public_html/test.php有效的图像资源上线

免费虚拟主机
PHP错误信息
警告:imagecolorallocate():提供的参数不是在/home/a5838755/public_html/test.php有效的图像资源上线

免费虚拟主机
PHP错误消息
警告:imagettfbbox()[function.imagettfbbox]:找不到/开放字体在/home/a5838755/public_html/test.php上线

免费的虚拟主机
PHP错误信息
警告:imagettftext()预计参数1是资源,布尔上线/home/a5838755/public_html/test.php给出

免费虚拟主机
PHP错误信息
警告:imagejpeg():提供的参数不是在/HO有效的图像资源我/ a5838755 /的public_html/test.php的上线

免费的虚拟主机
PHP错误信息
警告:imagedestroy():提供的参数不是在/家庭有效的图像资源/ a5838755 /的public_html /测试。在线PHP

免费的虚拟主机

1

我也有类似的问题。就我而言,事实上我的<?php标签上方有一些空格。当我删除它们时,它工作完美。我希望你的问题和我一样简单。

+0

非常感谢。 – Sayka