1

So I found the perfect example of a page I would like to download images from, this so happens to be http://www.habbo.com/habbo-imaging/avatarimage?figure=ch-215-110.hd-180-7.lg-275-110.hr-893-61&direction=3&head_direction=3&headonly=1&gesture=sml&size=1

Now, when you go to save the image if you were to on your desktop, it reads as a PNG file, although I am trying to save it using PHP but I want it to save as GIF.

What I've so far is:

$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);

I managed to get the permissions working and a image saves, but it's saving just the file name and the photo isn't there. So I'm guessing it has something to do with me saving a PNG file as a GIF, surely there's something I'm missing.

Liam
  • 41
  • 1
  • 7
  • Try copy('https://www.habbo.com/habbo-imaging/avatarimage?figure=hr-125&direction=3&head_direction=3&headonly=1&gesture=sml&size=1', 'game/c_images/badges/' . $badge_id . '.gif'); – Rahul Dec 16 '16 at 09:48
  • Instead of the whole script @RahulMeshram ? – Liam Dec 16 '16 at 09:51
  • Using copy() results in: – Liam Dec 16 '16 at 09:52
  • Warning: copy(http://habbo.com/habbo-imaging/avatarimage?figure=ch-215-110.hd-180-7.lg-275-110.hr-893-61&direction=3&head_direction=3&headonly=1&gesture=sml&size=1): failed to open stream: HTTP request failed! HTTP/1.1 – Liam Dec 16 '16 at 09:53
  • @copy('https://www.habbo.com/habbo-imaging/avatarimage?figure=ch-215-110.hd-180-7.lg-275-110.hr-893-61&direction=3&head_direction=3&headonly=1&gesture=sml&size=1','game/c_images/badges/' . $badge_id . '.gif'); can you check this ? check for protocols, I am getting https – Rahul Dec 16 '16 at 09:56
  • read this thread: http://stackoverflow.com/questions/7967531/php-curl-writing-to-file – 2oppin Dec 16 '16 at 10:16

1 Answers1

1

yes,You can save image using html dom. like use

   `$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";`
ashish mulani
  • 197
  • 1
  • 14