0

I tried the following but it takes too long to process:

imagepng(imagecreatefromstring(file_get_contents($input)), $output);

where the $input is an animated GIF.

Any idea how to convert a large animated GIF to a still PNG in PHP fast? I simply need the first frame of the GIF image converted to PNG, fast.

BunkBedNoob
  • 367
  • 1
  • 4
  • 15

1 Answers1

0

Just use imagecreatefromgif:

imagepng(imagecreatefromgif($input), $output);

http://php.net/manual/en/function.imagecreatefromgif.php

Jonathan Gray
  • 2,509
  • 15
  • 20
  • Well, it's probably the most efficient way you'll be able to do it. That PHP class is not meant to be used with large image files. PHP itself shouldn't be used with large files regardless of type. I'm not able to test code at the moment (nor when I answered) but if used with smaller image files I guarantee it would be phenomenally more efficient. – Jonathan Gray Nov 28 '14 at 00:54
  • @BunkBedNoob I was the only one to answer you, and you could have found a more efficient way yourself had you even tried to find out yourself (I simply used Google and found imagecreatefromgif). You asked for an efficient way of doing something and you were given one. You're in no place to complain that it's not good enough. – Jonathan Gray Nov 28 '14 at 00:59
  • @BunkBedNoob by the way you're using GD, not ImageMagick. – Jonathan Gray Nov 28 '14 at 01:09
  • Yeah I know it's GD. I meant that the current solution I'm using works at same speed as your solution. I'll try ImageMagick and see if it improves the speed and update answer if true... – BunkBedNoob Nov 28 '14 at 06:08