【问题标题】:imagecreatefrompng errorimagecreatefrompng 错误
【发布时间】:2010-05-06 16:59:29
【问题描述】:
<?php
function LoadPNG($imgname)
{
    /* Attempt to open */
    $im = @imagecreatefrompng($imgname);

    /* See if it failed */
    if(!$im)
    {
        /* Create a blank image */
        $im  = imagecreatetruecolor(150, 30);
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc  = imagecolorallocate($im, 0, 0, 0);

        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);

        /* Output an error message */
        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }

    return $im;
}

header('Content-Type: image/png');

$img = LoadPNG('http://www.prideofhome.com/wp-content/uploads/328145505image_11.png');

imagepng($img);
imagedestroy($img);
?>

我收到错误。如何解决。imagecreatefrompng 不支持来自远程服务器的文件。

【问题讨论】:

    标签: php gd


    【解决方案1】:

    要使用来自远程服务器的文件,请将imagecreatefromstringfile_get_contents 结合使用:

    $im = imagecreatefromstring(file_get_contents($imgname));
    

    请注意,只有在启用了 fopen 包装器的情况下,才能将 URL 用作带有 file_get_contents 的文件名。

    如果这不能解决您的问题,请澄清您的问题。至少给出您收到的错误。 :)

    【讨论】:

      【解决方案2】:

      删除@ 会让您看到问题所在。 apppropriate option 未设置,或者 gd 扩展是在不支持 PNG 的情况下构建的,或者远程文件不存在/无法下载。

      【讨论】:

        猜你喜欢
        • 2018-11-30
        • 2012-02-19
        • 2011-06-10
        • 1970-01-01
        • 2017-12-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-18
        相关资源
        最近更新 更多