php从图像内容字符串中获取图像大小

php从图像内容字符串中获取图像大小,php,imagemagick,gd,Php,Imagemagick,Gd,我有一个函数,可以通过CURL获取远程图像,返回远程图像内容的字符串变量 我不希望将内容写入文件,但希望获得图像的大小 由于getimagesize()只支持文件,是否有类似于getimagesize()但可以支持图像内容字符串的函数 澄清: $image_content = file_get_contents('http://www.example.com/example.jpg'); 如何获取$image\u content的图像大小,而不是运行getimagesize('http://w

我有一个函数,可以通过CURL获取远程图像,返回远程图像内容的字符串变量

我不希望将内容写入文件,但希望获得图像的大小

由于getimagesize()只支持文件,是否有类似于getimagesize()但可以支持图像内容字符串的函数

澄清:

$image_content = file_get_contents('http://www.example.com/example.jpg');
如何获取
$image\u content
的图像大小,而不是运行
getimagesize('http://www.example.com/example.jpg');

提前感谢

PHP函数和

像这样的东西

$image_content = file_get_contents('http://www.example.com/example.jpg');
$image = imagecreatefromstring($image_content);
$width = imagesx($image);
$height = imagesy($image);

仅供参考,对于那些在游戏中迟到的人,PHP>=5.4现在包括
getimagesizefromstring()
,它与
getimagesize()
相同,但接受第一个参数的字符串而不是位置


好的,我找到了PHP5.3及以下版本的答案

if (!function_exists('getimagesizefromstring')) {
    function getimagesizefromstring($data)
    {
        $uri = 'data://application/octet-stream;base64,' . base64_encode($data);
        return getimagesize($uri);
    }
}

图像尺寸或文件大小?@Dagon图像尺寸。我怀疑可以通过
strlen()
实现文件大小。