denn1s
denn1s

Reputation: 155

imagecreatefromgif() returning is not a valid GIF file in

I am trying to pull an image from a .php file on an external site which is a gif (one frame). I want to in the end put these images into a gif but thats not the problem at the moment. Everytime i try to save down the gifs as .pngs it returns the error " is not a valid GIF file in"

include('GIFEncoder.class.php');
$user = $_GET['user'];
$url = 'http://link.com/image.php?username=' . $user . '';
$username = explode('=', $url);
$username = $username[1];
$img = 'image_cache/' . $username .'.gif';
file_put_contents($img, file_get_contents($url));
$i = imagecreatefromgif('image_cache/' . $username .  '.gif');
imagepng($i, "image_cache/". $username .".png");

the exact error im getting

Warning: imagecreatefromgif() [function.imagecreatefromgif]: 'image_cache/Lexo.gif' is not a valid GIF file in z/projects/gif/index.php on line 9

Upvotes: 1

Views: 3164

Answers (3)

Doddanna D
Doddanna D

Reputation: 41

try this code to fixe the issue somefilename is not a valid GIF file in..imagecreatefromgif()

$createFrom = imagecreatefromstring(file_get_contents($filepath));
imagecopyresampled();
imagegif();

Upvotes: 0

StackSlave
StackSlave

Reputation: 10627

Your code should look more like:

if(isset($_GET['user'])){
  header('Content-type:image/png');
  $user = $_GET['user']; $img = imagecreatefrompng("image_cache/$user.png");
  imagepng($img); imagedestroy($img);
}

Upvotes: 0

jameslafferty
jameslafferty

Reputation: 2182

The image is actually a png. Run exif_imagetype on the file, and you'll see that the type is png. The gif suffix is a mistake. To do what you're trying to do, just name it with a .png suffix.

Upvotes: 2

Related Questions