1

这是我一直在尝试做的,但它总是显示损坏的图像。我什至启用了错误报告,但一切似乎都恢复正常......只是没有显示图像。:(

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);
?>
4

2 回答 2

1

您的脚本的输出如下。如果您删除您的内容类型标头,或者使用诸如 Fiddler 之类的工具,您可以自己看到这一点。此外,有了这些“免费网络托管”行,您将永远无法使用它。



PHP 错误消息
警告:imagecreatefrompng(calendar_blank.png) [function.imagecreatefrompng]:无法打开流:第13行的/home/a5838755/public_html/test.php中没有此类文件或目录免费虚拟主机PHP 错误消息警告:imagesx ():提供的参数不是第14/home/a5838755/public_html/test.php中的有效图像资源免费虚拟主机PHP 错误消息警告:imagecolorallocate():提供的参数不是/home/a5838755中的有效图像资源/public_html/test.php17行免费虚拟主机PHP 错误消息警告











:imagettfbbox()[function.imagettfbbox]:无法在第22行的/home/a5838755/public_html/test.php中找到/打开字体免费虚拟主机PHP错误消息警告:imagettftext()期望参数1是资源,给定的布尔值在第27行的/home/a5838755/public_html/test.php免费 Web 托管PHP 错误消息警告:imagejpeg():提供的参数不是第36行的/home/a5838755/public_html/test.php中的有效图像资源Free Web托管PHP 错误消息警告:imagedestroy():提供的参数不是有效的图像资源











/home/a5838755/public_html/test.php在线39

免费虚拟主机

于 2012-09-11T04:37:57.447 回答
1

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

于 2013-09-14T22:46:03.253 回答