15

I'd like to be able to take a 1-frame SWF file and convert it to PNG through PHP. I'm okay with using command-line tools to get this done.

How could I go about doing this? I found an ActiveX library, but that seems like one too many layers. I also see that Gnash seems to have a PNG output class, but I can't figure out how to get to that from the command line without doing some deep coding of my own. Are there any other clever solutions available? Thanks!

EDIT: To clarify, this is not a one-time task I just want to be able to do once. I'd like to be able to have a PHP script perform this task on command. Thanks!

Another EDIT: One more clarification. This is not a situation in which, say, a user makes a drawing in Flash. I am downloading raw 1-frame SWF files, and want to save PNG copies in order to reduce download time. Is such a task possible? Thanks again!

4 Answers 4

23

you can use swftools.
swfrender file.swf -X pixelsize -Y pixelsize -o output.png

If only one between -X -Y parameter is specified then proportions are respected

4
  • Odd. I had looked up swftools but somehow missed that particular tool that does exactly what I need. I'll check on that later today :)
    – Matchu
    Commented Jan 5, 2010 at 17:19
  • Seems to work instantly - and to think I already had this installed! Thanks!
    – Matchu
    Commented Jan 5, 2010 at 17:30
  • 1
    Sadly, this doesn't seem to work well with transparent backgrounds. Awesome tool though. One of our off shore developers is trying to suggest SWFToVideo but its $1000 for a license........ :( sad face Commented Dec 30, 2011 at 14:21
  • swfrender worked for my test case but sadly there is no option to select the zoom factor for rendering so I'm left with a way too small rendering where the text parts are illegible. Commented May 27, 2012 at 22:20
2

Depending on the type of swf's you have you could try FFmpeg from the command line:

ffmpeg -i movie.swf -f image2 -vcodec png movie%d.png
5
  • "[swf @ 0x9b822c0]Compressed SWF format not supported" - drat. Trying to Google a way out of this - apparently I should be able to build a tool that will decompress it...
    – Matchu
    Commented Jan 4, 2010 at 20:42
  • 1
    Interesting. Now PNG is listed as one of ffmpeg's formats, but I get "could not find codec parameters" anyway. I'll keep working on it.
    – Matchu
    Commented Jan 4, 2010 at 21:38
  • It looks like ffmpeg can only convert some swf formats, depending what they include.
    – o0'.
    Commented May 30, 2011 at 10:04
  • 1
    @Lo'oris: That's why my answer says it might work depending on the type of .swf.
    – cOle2
    Commented May 30, 2011 at 14:50
  • I used swfcombine to decompress the swf which made avconv (ffmpeg fork) accept it and produced two pngs but these where not renderings of the swf but just the two images contained in the swf so it seems more like an alternativeswfextract to me. Commented May 27, 2012 at 22:30
2

See From Google: Flash screenshot

3
  • I'd prefer to start with server-side technologies, then try client-side, since there will always be malicious users out there. But thanks - I'll keep it in mind :)
    – Matchu
    Commented Jan 4, 2010 at 20:36
  • 2
    The point of the article is that the screenshot is taken in Flash. You can do whatever you want with that image at that point. Commented Jan 4, 2010 at 20:50
  • PHP will let you write that png to the server using a filestream. It's going to use the same mechanism within Flash to encode the .png data, then you just send the byte array to your PHP method.
    – Myk
    Commented Jan 5, 2010 at 1:34
1

not really a server based solution, but i developed an AIR utility to convert SWF to PNG sequences: http://swfrenderer.kurst.co.uk/

1
  • This gets a +1 from me. After hours of searching and testing, this is the only thing that will work in reliably exporting an SWF to png sequence with embedded movie clips. Even the v1 AIR app still works perfectly with a CS6 SWF.
    – indextwo
    Commented Jun 3, 2017 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.