0

Why i can not use getimagesize PHP with this image ?

For this image i can get getimagesize PHP, work good.

<?PHP
        $source = "https://i.pinimg.com/736x/da/7a/19/da7a19a0c3daabe579ecca21d1ae32c3--felt-wool-felting-projects.jpg";
        $dimension = getimagesize($source);
        $width = $dimension[0];
        $height = $dimension[1];

        echo $width;
        echo "<BR>";
        echo $height;
?>

But for this image Why i can not get getimagesize PHP ?

<?PHP
        $source = "https://shorebread.com/wp-content/uploads/2016/07/kitty-cat-reaching_138482216-2000x500.jpg";
        $dimension = getimagesize($source);
        $width = $dimension[0];
        $height = $dimension[1];

        echo $width;
        echo "<BR>";
        echo $height;
?>

How can i do for use getimagesize PHP on every image ?

1 Answers1

1

It could be that the website doesn't allow "hot-linking" or that it blocks PHP's user agent.

If you try getting the data from the URL you will get a HTTP/1.1 403 Forbidden response:

php > $dimension = getimagesize($source);
PHP Warning:  getimagesize(https://shorebread.com/wp-content/uploads/2016/07/kitty-cat-reaching_138482216-2000x500.jpg):        
 failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

 in php shell code on line 1

If you download the image first, and do the same from disk it works:

php > $dimension = getimagesize("kitty-cat-reaching_138482216-2000x500.jpg");
php > print_r($dimension);
Array
(
    [0] => 2000
    [1] => 500
    [2] => 2
    [3] => width="2000" height="500"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
)

So it is not that getimagesize doesn't work on all images. It couldn't download the image itself.

Eduardo Romero
  • 1,159
  • 8
  • 10