如何从PHP中的URL获取图像的大小?

时间:2017-12-20 04:13:02

标签: php image size

我一直试图从网址中获取图片的大小,但它无法正常工作。谁能帮我?

这是代码:

$imagesize = getimagesize('https://www.dropbox.com/s/hbtmge2omlyqx2n/BrownBag.jpg?dl=0');
echo $imagesize;

2 个答案:

答案 0 :(得分:1)

您未在此网址中获取图片https://www.dropbox.com/s/hbtmge2omlyqx2n/BrownBag.jpg?dl=0

您需要获得的是图片地址 https://photos-5.dropbox.com/t/2/AADa4bq7fis50BvRTojhB5zvAJDLNwsLDb5dekkb4JfilQ/12/502094097/jpeg/32x32/3/1513760400/0/2/BrownBag.jpg/EJrFv4kEGLgCIAIoAg/cwCCXcZopeYId4BrstNKJ6qGETjrin47oEgU6B50AE0?dl=0&size=1280x960&size_mode=3

<强>代码

$imagesize = getimagesize('https://photos-5.dropbox.com/t/2/AADa4bq7fis50BvRTojhB5zvAJDLNwsLDb5dekkb4JfilQ/12/502094097/jpeg/32x32/3/1513760400/0/2/BrownBag.jpg/EJrFv4kEGLgCIAIoAg/cwCCXcZopeYId4BrstNKJ6qGETjrin47oEgU6B50AE0?dl=0&size=1280x960&size_mode=3');
print_r($imagesize);

<强>结果

Array
(
    [0] => 1000
    [1] => 750
    [2] => 2
    [3] => width="1000" height="750"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
)

您也可以参考此Dropbox get public url of the file after upload

简单地改变:

https://www.dropbox.com/s/hbtmge2omlyqx2n/BrownBag.jpg?dl=0

https://dl.dropbox.com/s/hbtmge2omlyqx2n/BrownBag.jpg

只需将www替换为dl,然后移除?dl=0

答案 1 :(得分:0)

您需要使用dropbox的图像路径

$imagesize = getimagesize('https://photos-5.dropbox.com/t/2/AADa4bq7fis50BvRTojhB5zvAJDLNwsLDb5dekkb4JfilQ/12/502094097/jpeg/32x32/3/1513760400/0/2/BrownBag.jpg/EJrFv4kEGLgCIAIoAg/cwCCXcZopeYId4BrstNKJ6qGETjrin47oEgU6B50AE0?dl=0&size=1600x1200&size_mode=3');
echo $imagesize;