getimagesizefromstring
(PHP 5 >= 5.4.0, PHP 7, PHP 8)
getimagesizefromstring — 从字符串中获取图像尺寸信息
说明
getimagesizefromstring(string
$imagedata
, array &$imageinfo
= ?): array同 getimagesize() 函数。 区别是 getimagesizefromstring() 第一个参数是图像数据的字符串表达,而不是文件名。
关于本函数如何工作的更多信息请参见 getimagesize() 函数。
参数
-
imagedata
-
图像数据的字符串表示。
-
imageinfo
-
参见 getimagesize() 函数。
返回值
参见 getimagesize() 函数。
范例
示例 #1 getimagesizefromstring() 函数例程
<?php
$img = '/path/to/test.png';
// 以文件方式打开
$size_info1 = getimagesize($img);
// 以字符串格式打开
$data = file_get_contents($img);
$size_info2 = getimagesizefromstring($data);
?>

User Contributed Notes 2 notes
imageman ¶
8 years ago
getimagesizefromstring function for < 5.4
<?php
if (!function_exists('getimagesizefromstring')) {
function getimagesizefromstring($string_data)
{
$uri = 'data://application/octet-stream;base64,' . base64_encode($string_data);
return getimagesize($uri);
}
}
?>
sarah at anigel dot net ¶
8 years ago
Just a quick comment on the solution by imageman for versions < 5.4 you will need to enable allow_url_fopen in order to use the data wrapper.
备份地址:http://www.lvesu.com/blog/php/function.getimagesizefromstring.php