Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if .swf has transparent background

Is there a way to do this programmatically in PHP, Python or Java?

Use case:

  • User uploads .swf through an upload form.
  • Detect if it has a transparent background.
  • If it does, change it to something else, e.g. white.
like image 602
smottt Avatar asked May 13 '11 06:05

smottt


4 Answers

This is very difficult to determine, because all SWFs are actually transparent (or they all can be) - it's just that they can contain shapes which cover the entire stage, which make them appear non-transparent.

To determine this programmatically, you'd need to loop over every shape in the SWF and look at it's bounds. However, that wont be enough since any shapes can be changed by ActionScript blocks and new shapes can be created at run time.

But really, making them transparent is the hard task. Since you want to make sure they're are non-transparent, you can just deal with this at display time - put a colored div behind the object or embed tag.

like image 188
Cal Avatar answered Nov 07 '22 22:11

Cal


Probably impossible. I suggest a checkbox on the upload form "This flash app looks best with a transparent background".

Here is a flash app that has - a transparent background to start - a slider that lets you adjust the opacity

As you can see it would be impossible to say "transparent" or "opaque"

like image 24
James Avatar answered Nov 07 '22 23:11

James


As far as I know you can't get the background alpha (transparency) of a swf file. what I would do if I were you would put the uploaded swf into a container swf (load the uploaded swf inside it) which only has a background color of your choice.

There used to be a php swf reader in this link. But I didn't see any alpha information in it aswell.

like image 1
frail Avatar answered Nov 07 '22 23:11

frail


Flash is a bunch of compiled binary data. You Might be able to hunt down a third party library which can un-compile the flash file and get some of the data from the root movie scene, but it's a large stretch. As others have recommended, a checkbox during upload would be the best route to take.

like image 1
Thomas Hunter II Avatar answered Nov 07 '22 22:11

Thomas Hunter II