Skip to content
Advertisement

getimagesize and https

I am retrieving facebook album images from facebook.I have calculating the image size using the php function getimagesize.This function is working fine when the url is in http mode.When the facebook return the image url with https the getimagesize giving error.How i can calculate the imagesize of images with https extension using getimage size

Advertisement

Answer

You do not have the OpenSSL extension installed in your PHP instance, so the https:// wrapper is not available.

From the manual:

Note: HTTPS is only supported when the openssl extension is enabled.

And:

To use PHP’s OpenSSL support you must also compile PHP –with-openssl[=DIR] .

You will need to recompile PHP with the OpenSSL extension.

Alternatively, as suggested by others, you can replace the https:// with http://, which for Facebook images should work just as well – indeed, it may be quicker, and will certainly be more bandwidth efficient.

I would do that like this:

$url = 'https://facebook.com/path/to/image.jpg';
$url = trim($url); // Get rid of any accidental whitespace
$parsed = parse_url($url); // analyse the URL
if (isset($parsed['scheme']) && strtolower($parsed['scheme']) == 'https') {
  // If it is https, change it to http
  $url = 'http://'.substr($url,8);
}

Another point about that is that passing $url directly in to getimagesize() is probably not what you want to be doing. It is unlikely that the only thing you would be doing with the image is getting it’s size, you will probably be displaying it on your page or otherwise manipulating it, and if this were the case your will end up downloading it more than once.

You should probably download it to a temporary directory, then work on a local copy of it.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement