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

ric*_*pai 5 php gd imagemagick

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

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

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

澄清:

$image_content = file_get_contents('http://www.example.com/example.jpg');
Run Code Online (Sandbox Code Playgroud)

如何获取图像大小$image_content而不是运行getimagesize('http://www.example.com/example.jpg');

提前致谢

And*_*ewR 11

PHP函数imagecreatefromstring,imagesximagesy.

像这样的东西;

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


ouc*_*cil 6

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

http://php.net/manual/en/function.getimagesizefromstring.php