Reputation: 72580
I've been given a Flash file (.swf
extension) to put into a web page. Opening the file in my browser makes it quite blurry, so I'm assuming there is a natural size for the file, same as an image.
It's also rectangular so I need to work out the aspect ratio if I don't have an exact size. How would I find this information out?
Upvotes: 14
Views: 15091
Reputation: 11
import zlib, lzma
def getswfdimension(fname):
with open(fname, 'rb') as f:
buf = f.read()
sig = buf[:3].decode('ascii')
d = None
if sig == 'FWS':
# uncompressed
d = buf[8:]
elif sig == 'CWS':
d = zlib.decompress(buf[8:])
elif sig == 'ZWS':
d = lzma.decompress(buf[8:])
if not d:
print('unknown file format')
return
nbits = d[0]>>3
bstr=''
for i in range(32):
bstr += '{:08b}'.format(d[i])
bstr = bstr[5:]
w = int( bstr[ nbits : 2*nbits], 2) # width in twips
h = int (bstr[3*nbits: 4*nbits], 2)
# width x height in pixel
print("{} {} x {}".format(fname, int(w/20), int(h/20)))
Upvotes: 0
Reputation: 15194
After years I finally found a little tool that does exactly one thing: Displaying the height and width of a flash file. I cannot believe that Adobe never realized that knowing the size of a flash program is important.
Here you go: https://github.com/q2apro/swfinfo/raw/master/swfinfo.swf
I could not find the original source, please credit the developer if you know about. Thanks.
Upvotes: 8
Reputation: 41
I made script to detect dimensions of remote swf and print embed code of file.
http://www.igrice-tigrice.com/flash-dimensions.php
Upvotes: 3
Reputation: 56998
I was wondering how to get this myself last night. Didn't find anything on google, but then I remembered that PHP's getimagesize
works on swf movies:
<?php
$file = "YOUR_FILE.swf";
$info = getimagesize($file);
$width = $info[0];
$height = $info[1];
print "{$width}x{$height}\n";
?>
Upvotes: 23