PHP和GD破碎的图像

时间:2012-09-11 04:21:03

标签: php image 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);
?>

2 个答案:

答案 0 :(得分:1)

您的脚本输出如下。如果删除内容类型标题或使用Fiddler等工具,您可以自己查看。此外,有了那些“免费网络托管”线路,你永远不会让它工作。



PHP错误消息
警告:imagecreatefrompng(calendar_blank.png)[function.imagecreatefrompng]:无法打开流: /home/a5838755/public_html/test.php 上没有此类文件或目录 13
免费虚拟主机
PHP错误消息
警告:imagesx():提供的参数不是 /home/a5838755/public_html/test.php 中有效的图像资源 14 <登记/>
免费虚拟主机
PHP错误消息
警告:imagecolorallocate():提供的参数不是 /home/a5838755/public_html/test.php 中有效的图像资源 17 <登记/>
免费虚拟主机
PHP错误消息
警告:imagettfbbox()[function.imagettfbbox]:无法在 /home/a5838755/public_html/test.php 22 中找到/打开字体

免费虚拟主机
PHP错误消息
警告:imagettftext()要求参数1为资源,在 /home/a5838755/public_html/test.php 27 <中给出布尔值登记/>
免费虚拟主机
PHP错误消息
警告:imagejpeg():提供的参数不是 /home/a5838755/public_html/test.php 中有效的图像资源 36 <登记/>
免费虚拟主机
PHP错误消息
警告:imagedestroy():提供的参数不是 /home/a5838755/public_html/test.php 中有效的图像资源 39 <登记/>
免费虚拟主机

答案 1 :(得分:1)

我有类似的问题。在我的情况下,我的<?php标签上方有一些空格。当我删除它时,它完美地工作。我希望你的问题和我的一样简单。