rhog23
rhog23

Reputation: 321

How to get the size of an image from a url in php?

I've been trying to get the size of an image from a url, but it's not working. Can anyone help me?

This is the code:

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

Upvotes: 7

Views: 9380

Answers (2)

JJJJ
JJJJ

Reputation: 1338

You're not getting the image https://www.dropbox.com/s/hbtmge2omlyqx2n/BrownBag.jpg?dl=0 in this url

What you need to get is the image address which is this 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

Code

$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);

Result

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

You can also refer to this Dropbox get public url of the file after upload

Simply change:

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

to

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

Just replace www with dl and remove ?dl=0

Upvotes: 9

Shalitha Suranga
Shalitha Suranga

Reputation: 1146

You need to use the image path of 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;

Upvotes: 0

Related Questions