flash_tool 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of flash_tool might be problematic. Click here for more details.
- data/.gitignore +1 -0
- data/README.rdoc +63 -15
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/flash_tool.gemspec +28 -18
- data/lib/flash_tool.rb +76 -170
- data/lib/flash_tool/flash.rb +114 -0
- data/lib/flash_tool/flash_combine.rb +82 -0
- data/lib/flash_tool/flash_object.rb +73 -0
- data/lib/flash_tool/flash_script.rb +36 -0
- data/test/{25-1.gif → test_files/25-1.gif} +0 -0
- data/test/test_files/bad.sc +1 -0
- data/test/{bad_ext.txt → test_files/bad_ext.txt} +0 -0
- data/test/{bad_swf.swf → test_files/bad_swf.swf} +0 -0
- data/test/{jpeg.swf → test_files/jpeg.swf} +0 -0
- data/test/{liberationserif_bold.ttf → test_files/liberationserif_bold.ttf} +0 -0
- data/test/{rfxview.swf → test_files/rfxview.swf} +0 -0
- data/test/test_files/script.sc +8 -0
- data/test/{test.jpg → test_files/test.jpg} +0 -0
- data/test/{test.pdf → test_files/test.pdf} +0 -0
- data/test/{test.png → test_files/test.png} +0 -0
- data/test/{test_with_password.pdf → test_files/test_with_password.pdf} +0 -0
- data/test/{tester.swf → test_files/tester.swf} +0 -0
- data/test/test_flash_combine.rb +88 -0
- data/test/test_flash_object.rb +230 -0
- data/test/test_flash_script.rb +52 -0
- data/test/test_flash_tool.rb +47 -140
- metadata +27 -17
- data/test/test_flash_data.rb +0 -69
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
= Flash Tool
|
2
2
|
|
3
|
-
A ruby wrapper for swftool command line tool. http://www.swftools.org
|
3
|
+
A ruby wrapper for swftool command line tool. http://www.swftools.org
|
4
4
|
|
5
5
|
Flash tool is small and mini tool for creating swf files from pdfs, pictures and
|
6
6
|
fonts and parsing data from flash files.
|
7
7
|
|
8
|
+
|
9
|
+
== Install
|
10
|
+
|
11
|
+
gem install flash_tool
|
12
|
+
|
8
13
|
== Use
|
9
14
|
|
10
15
|
With this wrapper you commands from swftools program.
|
@@ -14,13 +19,15 @@ With Flash tool you can easely creates and manipulates flash files.
|
|
14
19
|
|
15
20
|
== Creating flash files
|
16
21
|
|
22
|
+
=== Creataing flash files from documents
|
23
|
+
|
17
24
|
With Flash tool you can create swf file from pdf, jpeg (jpeg and jpg extension),
|
18
25
|
png, gif, fonts (ttf, afm, pfa, pfb formats) and wav(this funcionality is untested
|
19
26
|
and you can often have problems with SWFTools installation with command wav2swf)
|
20
27
|
|
21
28
|
Simple creating flash object from pdf file
|
22
29
|
|
23
|
-
swfile = FlashObject.new('path_to_file.pdf')
|
30
|
+
swfile = FlashTool::FlashObject.new('path_to_file.pdf')
|
24
31
|
swfile.pages('1-10')
|
25
32
|
swfile.jpegquality('80')
|
26
33
|
swfile.save('outputfile_path.swf') # no need to declare ouptutfile_path in save if you used swfile.output() method before
|
@@ -29,7 +36,7 @@ Creating file from other format is very similar
|
|
29
36
|
|
30
37
|
Example for jpg
|
31
38
|
|
32
|
-
swfile = FlashObject.new('path_to_file.jpg')
|
39
|
+
swfile = FlashTool::FlashObject.new('path_to_file.jpg')
|
33
40
|
swfile.output('outputfile_path.swf')
|
34
41
|
swfile.save()
|
35
42
|
|
@@ -37,55 +44,96 @@ Flash tool automaticly recognize extension of file and call propriete SWFTool pr
|
|
37
44
|
If you use files without extension you just simply add string of extension when
|
38
45
|
initialize FlashObject
|
39
46
|
|
40
|
-
swfile = FlashObject.new('path_to_file','jpg')
|
47
|
+
swfile = FlashTool::FlashObject.new('path_to_file','jpg')
|
41
48
|
|
42
49
|
You can use tempfile
|
43
50
|
|
44
|
-
swfile = FlashOject.from_blob('path_to_file','jpg')
|
51
|
+
swfile = FlashTool::FlashOject.from_blob('path_to_file','jpg')
|
45
52
|
|
46
53
|
Creating flash with viewer
|
47
54
|
|
48
|
-
swfile = FlashObject.new('path_to_file.pdf')
|
55
|
+
swfile = FlashTool::FlashObject.new('path_to_file.pdf')
|
49
56
|
swfile.pages('1-10')
|
50
57
|
swfile.viewer('path_to_viewer_file')
|
51
58
|
swfile.save('outputfile_path.swf')
|
52
59
|
|
60
|
+
You can use with the block
|
61
|
+
|
62
|
+
swfile = FlashTool::FlashObject.new('path_to_file.pdf') do |f|
|
63
|
+
f.pages('1-10')
|
64
|
+
f.viewer('path_to_viewer_file')
|
65
|
+
f.save('outputfile_path.swf')
|
66
|
+
end
|
67
|
+
|
53
68
|
SWFTool command will be called when you save object.
|
54
69
|
|
70
|
+
=== Creating flash from scritps
|
71
|
+
|
72
|
+
With SWFTool you can use scripts for creating flash files. More on http://wiki.swftools.org/index.php/Swfc
|
73
|
+
|
74
|
+
flash_object = FlashTool::FlashScript.new("path_to_script")
|
75
|
+
flash_object.save(output_file)
|
76
|
+
|
77
|
+
Other way
|
78
|
+
FlashTool::FlashScript.create("path_to_script","output_path")
|
79
|
+
|
80
|
+
It is possible to push flash data in variable
|
81
|
+
flash = FlashScript.flash_data("path_to_script")
|
82
|
+
|
83
|
+
or
|
84
|
+
|
85
|
+
flash_object = FlashTool::FlashScript.new("path_to_script")
|
86
|
+
flash = flash_object.cgi
|
87
|
+
|
88
|
+
|
55
89
|
==Parsing text from file
|
56
90
|
|
57
91
|
It is very simple
|
58
92
|
|
59
|
-
FlashTool.parse_text('path_to_file.swf')
|
93
|
+
FlashTool::FlashTool.parse_text('path_to_file.swf')
|
60
94
|
|
61
95
|
==Geting data from flash files
|
62
96
|
|
63
97
|
You can get data from flash files with swfdump tool
|
64
98
|
|
65
|
-
FlashTool.swfdump('path_to_file.swf', 'command') #use swfdump options http://www.swftools.org/swfdump.html
|
99
|
+
FlashTool::FlashTool.swfdump('path_to_file.swf', 'command') #use swfdump options http://www.swftools.org/swfdump.html
|
66
100
|
|
67
|
-
Don't use option text it is buggy, instead use method FlashTool.parse_text
|
101
|
+
Don't use option text it is buggy, instead that use method FlashTool.parse_text
|
68
102
|
With method swfdump output is string
|
69
103
|
|
70
104
|
Better way
|
71
105
|
|
72
|
-
FlashTool.(command) List of command can get from http://www.swftools.org/swfdump.html
|
106
|
+
FlashTool::FlashTool.(command) List of command can get from http://www.swftools.org/swfdump.html
|
73
107
|
|
74
108
|
Examples
|
75
|
-
FlashTool.rate(file) #return Float
|
76
|
-
FlashTool.width(file) #return Integer
|
77
|
-
FlashTool.height(file) #return Integer
|
78
|
-
FlashTool.frames(file) #return Integer
|
109
|
+
FlashTool::FlashTool.rate(file) #return Float
|
110
|
+
FlashTool::FlashTool.width(file) #return Integer
|
111
|
+
FlashTool::FlashTool.height(file) #return Integer
|
112
|
+
FlashTool::FlashTool.frames(file) #return Integer
|
79
113
|
|
80
114
|
Other methods returns String
|
81
115
|
|
82
116
|
All this methods call commands swfdump, every time you call method. If you want
|
83
117
|
to do it in one pass use
|
84
118
|
|
85
|
-
FlashTool.flash_info(file)
|
119
|
+
FlashTool::FlashTool.flash_info(file)
|
86
120
|
|
87
121
|
Returns hash with keys 'width', 'rate', 'height', 'frames', and all values are strings
|
88
122
|
|
123
|
+
== Flash combine
|
124
|
+
|
125
|
+
This is advance technique for combining flash files. It is possible to combine two or more flash files
|
126
|
+
More about this on http://www.swftools.org/swfcombine.html
|
127
|
+
For simple adding viewer use FlashObject and creating vith view method
|
128
|
+
|
129
|
+
flash = FlashCombine.new() do |f|
|
130
|
+
f.master(inputs)
|
131
|
+
f.slave("viewport",TEST_SWF)
|
132
|
+
f.rate(25)
|
133
|
+
f.output(output_file)
|
134
|
+
f.save()
|
135
|
+
end
|
136
|
+
|
89
137
|
|
90
138
|
|
91
139
|
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ fonts and parsing data from flash files."
|
|
12
12
|
gem.email = "milboj@gmail.com"
|
13
13
|
gem.homepage = "http://github.com/milboj/flash_tool"
|
14
14
|
gem.authors = ["Bojan Milosavljevic"]
|
15
|
-
gem.rubyforge_project = '
|
15
|
+
gem.rubyforge_project = 'flash_tool'
|
16
16
|
|
17
17
|
|
18
18
|
# gem.add_development_dependency "", ">= 0"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/flash_tool.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{flash_tool}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bojan Milosavljevic"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-23}
|
13
13
|
s.description = %q{A ruby wrapper for swftool command line tool. http://www.swftools.org/
|
14
14
|
Flash tool is small and mini tool for creating swf files from pdfs, pictures and
|
15
15
|
fonts and parsing data from flash files.}
|
@@ -27,29 +27,39 @@ fonts and parsing data from flash files.}
|
|
27
27
|
"VERSION",
|
28
28
|
"flash_tool.gemspec",
|
29
29
|
"lib/flash_tool.rb",
|
30
|
-
"
|
31
|
-
"
|
32
|
-
"
|
33
|
-
"
|
34
|
-
"test/
|
35
|
-
"test/
|
36
|
-
"test/
|
37
|
-
"test/
|
38
|
-
"test/
|
39
|
-
"test/
|
40
|
-
"test/
|
41
|
-
"test/
|
42
|
-
"test/
|
30
|
+
"lib/flash_tool/flash.rb",
|
31
|
+
"lib/flash_tool/flash_combine.rb",
|
32
|
+
"lib/flash_tool/flash_object.rb",
|
33
|
+
"lib/flash_tool/flash_script.rb",
|
34
|
+
"test/test_files/25-1.gif",
|
35
|
+
"test/test_files/bad.sc",
|
36
|
+
"test/test_files/bad_ext.txt",
|
37
|
+
"test/test_files/bad_swf.swf",
|
38
|
+
"test/test_files/jpeg.swf",
|
39
|
+
"test/test_files/liberationserif_bold.ttf",
|
40
|
+
"test/test_files/rfxview.swf",
|
41
|
+
"test/test_files/script.sc",
|
42
|
+
"test/test_files/test.jpg",
|
43
|
+
"test/test_files/test.pdf",
|
44
|
+
"test/test_files/test.png",
|
45
|
+
"test/test_files/test_with_password.pdf",
|
46
|
+
"test/test_files/tester.swf",
|
47
|
+
"test/test_flash_combine.rb",
|
48
|
+
"test/test_flash_object.rb",
|
49
|
+
"test/test_flash_script.rb",
|
50
|
+
"test/test_flash_tool.rb"
|
43
51
|
]
|
44
52
|
s.homepage = %q{http://github.com/milboj/flash_tool}
|
45
53
|
s.rdoc_options = ["--charset=UTF-8"]
|
46
54
|
s.require_paths = ["lib"]
|
47
|
-
s.rubyforge_project = %q{
|
55
|
+
s.rubyforge_project = %q{flash_tool}
|
48
56
|
s.rubygems_version = %q{1.3.6}
|
49
57
|
s.summary = %q{Simple and mini tool for creating swf (flash) files from pdf, jpg, png and gif with swftools}
|
50
58
|
s.test_files = [
|
51
|
-
"test/
|
52
|
-
"test/
|
59
|
+
"test/test_flash_script.rb",
|
60
|
+
"test/test_flash_combine.rb",
|
61
|
+
"test/test_flash_tool.rb",
|
62
|
+
"test/test_flash_object.rb"
|
53
63
|
]
|
54
64
|
|
55
65
|
if s.respond_to? :specification_version then
|
data/lib/flash_tool.rb
CHANGED
@@ -1,195 +1,101 @@
|
|
1
1
|
require 'tempfile'
|
2
|
+
require File.dirname(__FILE__) + '/flash_tool/flash_script.rb'
|
3
|
+
require File.dirname(__FILE__) + '/flash_tool/flash_object.rb'
|
4
|
+
require File.dirname(__FILE__) + '/flash_tool/flash.rb'
|
5
|
+
require File.dirname(__FILE__) + '/flash_tool/flash_combine.rb'
|
2
6
|
|
3
7
|
module FlashTool
|
4
8
|
class FlashToolError < RuntimeError
|
5
9
|
end
|
6
10
|
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# Raise exceptions
|
28
|
-
def initialize(input,type = nil, tempfile = nil)
|
29
|
-
@args = []
|
30
|
-
@tempfile = tempfile
|
31
|
-
@input = input
|
32
|
-
@type = type || input.split('.').last
|
33
|
-
@command = type_parser(@type)
|
34
|
-
|
35
|
-
raise FlashToolError, "File not found" unless File.exist?(input)
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
def self.from_blob(blob, ext)
|
40
|
-
begin
|
41
|
-
tempfile = Tempfile.new(['swf_tool', ext.to_s])
|
42
|
-
tempfile.binmode
|
43
|
-
tempfile.write(blob)
|
44
|
-
ensure
|
45
|
-
tempfile.close if tempfile
|
46
|
-
end
|
47
|
-
|
48
|
-
return self.new(tempfile.path, ext ,tempfile)
|
49
|
-
end
|
50
|
-
|
51
|
-
#
|
52
|
-
def save(output_path=nil)
|
53
|
-
if output_path
|
54
|
-
@args << "--output"
|
55
|
-
@args << output_path
|
11
|
+
# This class provides usefull utilities for getting informations from flash files
|
12
|
+
# ===<b>Important</b>
|
13
|
+
# Method FlashTool.text and options FlashTool.method_missing("text", "file") and
|
14
|
+
# swfdump("file","text") on same system don't work appropriate instead use method <b>parse_text</b>
|
15
|
+
#
|
16
|
+
class FlashTool
|
17
|
+
class <<self
|
18
|
+
# This method parse text from swf file.
|
19
|
+
# File must have extension swf
|
20
|
+
def parse_text(file)
|
21
|
+
# something is bad with this program don't send errors, and we must check for errors
|
22
|
+
# we must check file first
|
23
|
+
# by documetation swfdump --text need to do this but
|
24
|
+
raise FlashToolError, "File missing path: #{file}" unless File.exist?(file)
|
25
|
+
raise FlashToolError, "Wrong file type SWF path: #{file} " unless file =~ /(.swf)$/i
|
26
|
+
command = "swfstrings #{file}"
|
27
|
+
output = `#{command} 2>&1`
|
28
|
+
# if file have appropiate name but is something is wrong with him
|
29
|
+
raise FlashToolError, output if output =~/(errors.)$/
|
30
|
+
return output
|
56
31
|
end
|
57
|
-
run_command(@command,*@args << @input)
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
def method_missing(symbol, *args)
|
64
|
-
@args << ("--#{symbol}")
|
65
|
-
@args +=(args)
|
66
|
-
end
|
67
32
|
|
68
|
-
private
|
69
33
|
|
70
|
-
def type_parser input
|
71
|
-
case input.downcase
|
72
|
-
when "pdf"
|
73
|
-
command = "pdf2swf"
|
74
|
-
when "jpg", "jpeg"
|
75
|
-
command = "jpeg2swf"
|
76
|
-
when "png"
|
77
|
-
command = "png2swf"
|
78
|
-
when "gif"
|
79
|
-
command = "gif2swf"
|
80
|
-
when "ttf", "afm", "pfa", "pfb"
|
81
|
-
command = "font2swf"
|
82
|
-
when "wav"
|
83
|
-
command = "wav2swf"
|
84
|
-
else
|
85
|
-
raise FlashToolError, "Invalid type"
|
86
|
-
end
|
87
|
-
return command
|
88
|
-
end
|
89
34
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
35
|
+
# Call swfdump commands in shorter way
|
36
|
+
# Can be used any option from swfdump command
|
37
|
+
# in casess: width, heihght and frames returns Integer
|
38
|
+
# in case rate returns Float
|
39
|
+
# in all other casess retruns String
|
40
|
+
#
|
41
|
+
def method_missing(option, file)
|
42
|
+
text = self.swfdump(file, option)
|
43
|
+
option = option.to_s
|
44
|
+
if option == "width" || option == 'height' || option == 'frames'
|
45
|
+
return text.split(' ').last.to_i
|
46
|
+
elsif option == 'rate'
|
47
|
+
return text.split(' ').last.to_f
|
100
48
|
else
|
101
|
-
|
49
|
+
return text
|
102
50
|
end
|
103
51
|
end
|
104
|
-
command = "#{command} #{args.join(" ")}"
|
105
|
-
output = `#{command} 2>&1`
|
106
|
-
|
107
|
-
if $?.exitstatus != 0
|
108
|
-
raise FlashToolError, "SWF command (#{command.inspect}) failed: #{{:status_code => $?, :output => output}.inspect}"
|
109
|
-
else
|
110
|
-
output
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
# This method parse text from swf file.
|
121
|
-
# File must have extension swf
|
122
|
-
def FlashTool.parse_text(file)
|
123
|
-
# something is bad with this program don't send errors, and ther is no need to check for errors
|
124
|
-
# we must check file first
|
125
|
-
# by documetation swfdump --text need to do this but
|
126
|
-
raise FlashToolError, "File missing path: #{file}" unless File.exist?(file)
|
127
|
-
raise FlashToolError, "Wrong file type SWF path: #{file} " unless file =~ /(.swf)$/i
|
128
|
-
command = "swfstrings #{file}"
|
129
|
-
output = `#{command} 2>&1`
|
130
|
-
# if file have appropiate name but is something is wrong with him
|
131
|
-
raise FlashToolError, output if output =~/(errors.)$/
|
132
|
-
return output
|
133
|
-
end
|
134
|
-
|
135
|
-
def FlashTool.method_missing(option, file)
|
136
|
-
text = self.swfdump(file, option)
|
137
|
-
option = option.to_s
|
138
|
-
if option == "width" || option == 'height' || option == 'frames'
|
139
|
-
return text.split(' ').last.to_i
|
140
|
-
elsif option == 'rate'
|
141
|
-
return text.split(' ').last.to_f
|
142
|
-
else
|
143
|
-
return text
|
144
|
-
end
|
145
|
-
end
|
146
52
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
53
|
+
###
|
54
|
+
# Returns hash value with basic flash parameters
|
55
|
+
# Keys are [width, rate, height, frames] and
|
56
|
+
# values are kind of string
|
57
|
+
def flash_info(file)
|
58
|
+
args = ['width', 'rate', 'height', 'frames']
|
59
|
+
data = swfdump(file, args)
|
60
|
+
data.gsub!(/(-X)/, "width ")
|
61
|
+
data.gsub!(/(-Y)/, "height ")
|
62
|
+
data.gsub!(/(-r)/, "rate ")
|
63
|
+
data.gsub!(/(-f)/, "frames ")
|
158
64
|
|
159
|
-
|
65
|
+
return Hash[*data.split(' ')]
|
160
66
|
|
161
|
-
|
67
|
+
end
|
162
68
|
|
163
69
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
70
|
+
###
|
71
|
+
# This method is very similar to swfdump command http://www.swftools.org/swfdump.html
|
72
|
+
# Use longer options for this commands without --
|
73
|
+
# DON'T use option text that option don't work
|
74
|
+
# ===Examples
|
75
|
+
# FlashTool.swfdump('test.swf', 'rate')
|
76
|
+
#
|
77
|
+
# FlashTool.swfdump('test.swf', ['rate','width','height'])
|
78
|
+
def swfdump(file, option=nil)
|
79
|
+
command = 'swfdump'
|
80
|
+
if option
|
81
|
+
if option.kind_of? Array
|
82
|
+
option.collect! { |a| "--#{a}" }
|
83
|
+
option = option.join(' ')
|
84
|
+
else
|
85
|
+
option = "--#{option}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
command = "#{command} #{option} #{file}"
|
89
|
+
output = `#{command} 2>&1`
|
90
|
+
if $?.exitstatus != 0
|
91
|
+
raise FlashToolError, "SWF command : #{command.inspect} failed : #{{:status_code => $?, :output => output}.inspect}"
|
92
|
+
else
|
93
|
+
return output
|
94
|
+
end
|
180
95
|
end
|
181
96
|
end
|
182
97
|
|
183
|
-
command = "#{command} #{option} #{file}"
|
184
|
-
|
185
|
-
output = `#{command} 2>&1`
|
186
|
-
if $?.exitstatus != 0
|
187
|
-
raise FlashToolError, "SWF command : #{command.inspect} failed : #{{:status_code => $?, :output => output}.inspect}"
|
188
|
-
else
|
189
|
-
return output
|
190
|
-
end
|
191
98
|
end
|
192
99
|
end
|
193
100
|
|
194
101
|
|
195
|
-
|