PHP Curl从VK保存动态图像

时间:2016-11-25 04:37:53

标签: php image curl save

我正在尝试将图像从VK保存到文件夹。但是图像无法正确保存。

我使用的代码是:

// imageFromURL (Save an image from a URL)
function imageFromURL($url,$saveto){
    $ch = curl_init ($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
    $raw=curl_exec($ch);
    curl_close ($ch);
    if(file_exists($saveto)){
        unlink($saveto);
    }
    $fp = fopen($saveto,'x');
    fwrite($fp, $raw);
    fclose($fp);
}

imageFromURL('https://vk.com/captcha.php?sid=698254154192&s=1', 'Image/Captcha.png');

我认为它一定不是标准的图像格式?我怎么能保存这个并确保它是一个带CURL的png格式图像?

1 个答案:

答案 0 :(得分:0)

您可以使用 0.0 16 -90.0 8 -100.0 5 -80.0 3 63.0 1 -50.0 1 130.0 1 190.0 1 840.0 1 -48.0 1 208.0 1 -64.0 1 812.0 1 -70.0 1 950.0 1 返回文件的图像类型。 PNG将返回3.

此外,您可以在保存之前进行检查:

exif_imagetype($image)

并检查您可能正在寻找的mime类型。请注意,那里有一些信任,因为您依靠远程服务器来正确报告该信息。