Last active
May 10, 2016 06:00
-
-
Save ksss/57447ddc14dca341c1c1ed80d5e5ca14 to your computer and use it in GitHub Desktop.
swfファイルのバイナリからRubyで縦横のサイズを取り出す ref: http://qiita.com/ksss/items/4736cb3922e10835ee96
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SwfFile | |
# @example: | |
# SwdFile.new("foo.swf") | |
def initialize(path) | |
@path = path | |
end | |
# @example: | |
# x_min, x_max, y_min, y_max = swf.stage_size | |
def stage_size | |
File.open(@path) do |io| | |
io.read(8) # header | |
# どんなに長くても 5+31*4 bitなので16byteで十分 | |
buf = io.read(16).bytes.map { |i| | |
"%08d" % i.to_s(2) | |
}.join | |
# 最初の5bitが以降の区切りの長さ(bit) | |
l = buf[0, 5].to_i(2) | |
# 最初の5bitを消しておく | |
buf[0, 5] = "" | |
[ | |
buf[0, l], # x_min | |
buf[l, l], # x_max | |
buf[l * 2, l], # y_min | |
buf[l * 3, l], # y_max | |
].map { |i| | |
# 1pt=20twips | |
i.to_i(2) / 20 | |
} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment