-3

Well, essentially, this is the script I'm using

<?php
$src = "http://upload.wikimedia.org/wikipedia/commons/4/4b/Everest_kalapatthar_crop.jpg";
$data = file_get_contents($src);
file_put_contents("picture.gif", $data);
$image = imagecreatefromgif("picture.gif");
?>

The last line was used to test how php would handle the image file, however php throws this error:

Warning: imagecreatefromgif() [function.imagecreatefromgif]: 'picture.gif' is not a valid GIF file
user1489795
  • 5
  • 1
  • 2
  • `file_put_contents` just deals with raw data, it doesn't know anything about images. Why did you think it would change an image from JPG to GIF? You think it cares about the filename suffix? – Barmar Dec 24 '12 at 02:34
  • Btw converting a photo like the one of Everest to GIF will greatly reduce the quality of the image if you want to maintain a sensible file size. Why are you trying to convert it to GIF? – kittycat Dec 24 '12 at 02:39
  • Only by changing the filename, you don't change the data in that file, for example you don't convert from jpeg to git image. – hakre Dec 24 '12 at 03:08
  • **FROMGIF**... unless you feed it an actual gif file, you'll get that error. – Marc B Dec 24 '12 at 03:46

2 Answers2

1

You could use imagecreatefromstring, these types will be automatically detected if your build of PHP supports them: JPEG, PNG, GIF, WBMP, and GD2.

xdazz
  • 158,678
  • 38
  • 247
  • 274
1

You're not that far off:

$src   = "http://upload.wikimedia.org/wikipedia/commons/4/4b/Everest_kalapatthar_crop.jpg";
$data  = file_get_contents($src);
$image = imagecreatefromstring($data);

Then do any extra steps in the conversion (optional, only if you like/need) and save as gif:

$saved = imagegif($image, "picture.gif");

See as well:

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836