PHP 的 getimagesize() 抛出 "SSL: The specified procedure could not be found"

PHP's getimagesize() throwing "SSL: The specified procedure could not be found"

我使用 php 的 getimagesize 对一小部分 (<5%) 测试的图像链接收到以下错误消息...

getimagesize(): SSL: The specified procedure could not be found.

这是一个抛出错误的示例(在我的 local/MAMP 服务器和实时版本上)...

getimagesize("https://cdn.meme.am/instances/500x/65858681.jpg");

有人知道如何进一步深入研究吗?真的不知道该去哪里,也找不到很多类似的问题。谢谢!

此代码将为您解决问题

 <?php
function getimgsize($url, $referer = '')
{
    $headers = array(
                    'Range: bytes=0-32768'
                    );

    /* Hint: you could extract the referer from the url */
    if (!empty($referer)) array_push($headers, 'Referer: '.$referer);

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($curl);
    curl_close($curl);

    $image = imagecreatefromstring($data);

    $return = array(imagesx($image), imagesy($image));

    imagedestroy($image);

    return $return;
}

list($width, $heigth) = getimgsize('https://cdn.meme.am/instances/500x/65858681.jpg', 'https://cdn.meme.am/instances/');

echo $width.' x '.$heigth;
?>