Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP从网站保存图像_Php_Image_Curl_Png_Gif - Fatal编程技术网

如何使用PHP从网站保存图像

如何使用PHP从网站保存图像,php,image,curl,png,gif,Php,Image,Curl,Png,Gif,所以我找到了一个我想从中下载图片的页面的完美例子,这恰好是 现在,如果要在桌面上保存图像,它将读取为PNG文件,虽然我尝试使用PHP保存它,但我希望它保存为GIF 到目前为止,我所做的是: $ch = curl_init('https://www.habbo.com/habbo-imaging/avatarimage?figure=hr-125&direction=3&head_direction=3&headonly=1&gesture=sml&size

所以我找到了一个我想从中下载图片的页面的完美例子,这恰好是

现在,如果要在桌面上保存图像,它将读取为PNG文件,虽然我尝试使用PHP保存它,但我希望它保存为GIF

到目前为止,我所做的是:

$ch = curl_init('https://www.habbo.com/habbo-imaging/avatarimage?figure=hr-125&direction=3&head_direction=3&headonly=1&gesture=sml&size=1');
$fp = fopen('game/c_images/badges/' . $badge_id . '.gif', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);

我成功地获得了权限并保存了一个图像,但它只保存了文件名,而照片不在那里。所以我猜这与我将PNG文件保存为GIF有关,当然我遗漏了一些东西

是的,您可以使用html dom保存图像。 喜欢使用

   `$new_image_name = '2018_'.mt_rand();
    $base_url = 'https://www.habbo.com/habbo-imaging/avatarimage?figure=hr-125&direction=3&head_direction=3&headonly=1&gesture=sml&size=1';
    $img = "./image_path/$new_image_name.jpg";
    file_put_contents($img,file($base_url));
    $local_image_url = "http://example.org/test/path_to_image/$new_image_name.jpg";`

尝试复制(“'game/c_images/badges/.$badge_id..gif”);使用copy()代替整个脚本@RahulMeshram?会导致:警告:copy():无法打开流:HTTP请求失败!HTTP/1。1@copy('.$badge_id..gif');你能检查一下这个吗?检查协议,我正在获取https