检查图像是否为空PHP

Rob*_*730 2 php image is-empty

我正在尝试制作一个PHP脚本来获取用户图片但是当我返回的图像为空时,它应该返回标准图像.这是我的代码不起作用......

<?php
if (isset($_GET['user']))
{
$user = $_GET['user'];
$skinURL = "http://s3.amazonaws.com/MinecraftSkins/".$user.".png";
} 
$debugImage = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/".$user.".png");
if (empty($debugImage)) // here it checks if $debugImage is empty (doesn't work)
{
    $skinURL = 'http://www.minecraft.net/images/char.png';
}
$skin = imagecreatefrompng($skinURL);
?>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

编辑1:如果图像存在,则链接返回图像,如果图像不存在则返回任何内容.非常感谢您的回答!

php*_*_qq 6

没有"空图像"这样的东西.即使它是空白图像,仍然存在具有相同颜色的像素,这将难以归类为"空".相反,为什么不检查文件是否存在?

function c_file_exists($file){
    $file_headers = @get_headers($file);
    if(strpos($file_headers[0], '404 Not Found')) {
        return false;
    }
    return true;
}
if (!c_file_exists("http://s3.amazonaws.com/MinecraftSkins/".$user.".png"))
{
    $skinURL = 'http://www.minecraft.net/images/char.png';
}
Run Code Online (Sandbox Code Playgroud)

资料来源:http://www.php.net/manual/en/function.file-exists.php#75064

编辑

我编辑了函数的条件以使用不同版本的HTTP,因为2现在已经出局,有人可能仍在使用1.0