function
myGetImageSize(
$url
,
$type
= 'curl',
$isGetFilesize
= false){
fread
方式
$type
=
$isGetFilesize
? '
fread
' :
$type
;
if
(
$type
== '
fread
')
{
if
(!
$handle
)
return
false;
$dataBlock
=
fread
(
$handle
, 168);
}
else
{
$ch
= curl_init(
$url
);
curl_setopt(
$ch
, CURLOPT_TIMEOUT, 5);
通过四张测试图读取宽高结果都没有问题,若获取不到数据可适当加大数值
curl_setopt(
$ch
, CURLOPT_RANGE, '0-167');
curl_setopt(
$ch
, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, true);
$dataBlock
= curl_exec(
$ch
);
curl_close(
$ch
);
if
(!
$dataBlock
)
return
false;
}
无须分别设置
$size
=
getimagesize
('data:
if
(
empty
(
$size
))
{
return
false;
}
$result
['width'] =
$size
[0];
$result
['height'] =
$size
[1];
{
$dataInfo
= isset(
$meta
['wrapper_data']['headers']) ?
$meta
['wrapper_data']['headers'] :
$meta
['wrapper_data'];
foreach
(
$dataInfo
as
$va
)
{
if
( preg_match('/length/iU',
$va
))
{
$ts
=
explode
(':',
$va
);
$result
['size'] = trim(
array_pop
(
$ts
));
break
;
}
}
}
if
(
$type
== '
fread
')
fclose(
$handle
);
return
$result
;
}
echo
'';
$result
= myGetImageSize
('http:
print_r(
$result
);
echo
'';
$result
= myGetImageSize
('http:
print_r(
$result
);
echo
'';
$result
= myGetImageSize
('http:
print_r(
$result
);
echo
'';
$result
= myGetImageSize
('http:
true);
print_r(
$result
);
echo
'';
$result
= myGetImageSize
('http:
print_r(
$result
);