Jump to content

Make thumbnail of SWF


Welling

Recommended Posts

Hi!

I'm trying to get thumbnails of SWF files in png or any other image format. I know there are desktop applications that do this but I would like to do this from php or with a linux program. Like I do with images I can't do with SWF because ImageMagick doesn't support SWF.

Any idea?

 

Thanks!

Link to comment
Share on other sites

  • 1 year later...

I found a few ways to get thumbnails from swf using php. Today I was researching if I could make a game site of mine handle uploads as I use Mochi media games for this moment only.

The first one is complicated- php-ffmpeg is a PECL extension that allows getting frames from avi, flv, mpg. It can't work with swf. There's a project you can use to convert swf to avi in php, but it uses some python stuff I couldn't make work on my Ubuntu. Maybe someone will try this approach. Just search for "pyvnc2swf" on google.

Another aproach is to take a browser screenshot. This was a successful strategy for me. There are two possible projects I found. The problem is that they can't work on a normal hosting machine. For video manipulation this is not such a problem though. There'a a class in phpclasses that uses Mozilla to capture images. It needs X installed. I couldn't try it, because I can't install libxul on Ubuntu 10.04, but I used a similar approach with a Windows XP virtual machine.

So... The steps I used to succeed:

1. Make the virtual host visible to the main machine. I didn't have such connection. It was simple- create a host adapter for the VM.

2. Install WAMP. Another windows apache+php bundles may need extra installation of COM support. For the scripts to work you need to make some administrative tasks- go to control panel- administrative tools - services. Select apache and in the properties window in Log On check "Allow this service to interract with desktop.".

3. Get the capture class from http://www.phpclasses.org/package/4608-PHP-Take-screenshots-of-pages-with-Internet-Explorer.html .

4. Patch the screenshot.class.php file this way:

- add a public $sleep=0; variable for the class

- patch the navigate function this way:

public function navigate( $url = 'about:blank' )

{

$url = ( $url ) ? $url : 'about:blank';

$this->IE->Navigate( ($url) ? $url : 'about:blank' );

$this->url = $url;

$time = time();

 

if ($this->sleep){

set_time_limit(100);

sleep($this->sleep);

}

while ( $this->IE->ReadyState != '4' and $time + 2 > time() )

{

$this->pump();

}

if ( $this->pump )

{

$this->pump( 1000 );

}

return true;

}

The code for sleep is mine.

5. Write a simple script to fetch images:

require_once('screenshot.class.php');

 

class_exists('screenshot') or die('screenshot class does not exist.');

 

$screen = new screenshot(false, 768, 1024);

$screen->sleep= 30;

$screen->navigate('http://hot2.kefche.net/games/d67wtx.swf');

$screen->title('You can set custom titles too (and custom body if you want)');

$screen->position(0, 0);

$screen->screenshot();

$screen->output();

$screen->save('image.jpg');

$screen->quit();

 

unset($screen);

 

Why do we need sleep(30)? When a flash game is loaded it has some loading time, advertising. The screenshot script without sleep would get the loading bar most of the times.

So... We have a really slow thumbnail system. What we need is some extra stuff for a queue of the swfs and sending images to the main server. A cron called once every 2-3 minutes for a thumb will help too. Maybe an infinite process with no cron is possible on a machine that servers thumbnails only.

 

The attached image is generated by the script I described.

 

http://dreamer79.eu , http://dreamerwebdesign.blogspot.com (blog in bulgarian language)

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.