A ruby wrapper for swftool command line tool. www.swftools.org
Flash tool is small and mini tool for creating swf files from pdfs, pictures and fonts and parsing data from flash files.
gem install flash_tool
With this wrapper you commands from swftools program.
SWFTools is a collection of utilities for working with Adobe Flash files. With Flash tool you can easely creates and manipulates flash files.
With Flash tool you can create swf file from pdf, jpeg (jpeg and jpg extension), png, gif, fonts (ttf, afm, pfa, pfb formats) and wav(this funcionality is untested and you can often have problems with SWFTools installation with command wav2swf)
Simple creating flash object from pdf file
swfile = FlashTool::FlashObject.new('path_to_file.pdf') swfile.pages('1-10') swfile.jpegquality('80') swfile.save('outputfile_path.swf') # no need to declare ouptutfile_path in save if you used swfile.output() method before
Creating file from other format is very similar
Example for jpg
swfile = FlashTool::FlashObject.new('path_to_file.jpg') swfile.output('outputfile_path.swf') swfile.save()
Flash tool automaticly recognize extension of file and call propriete SWFTool program If you use files without extension you just simply add string of extension when initialize FlashObject
swfile = FlashTool::FlashObject.new('path_to_file','jpg')
You can use tempfile
swfile = FlashTool::FlashOject.from_blob('path_to_file','jpg')
Creating flash with viewer
swfile = FlashTool::FlashObject.new('path_to_file.pdf') swfile.pages('1-10') swfile.viewer('path_to_viewer_file') swfile.save('outputfile_path.swf')
You can use with the block
swfile = FlashTool::FlashObject.new('path_to_file.pdf') do |f| f.pages('1-10') f.viewer('path_to_viewer_file') f.save('outputfile_path.swf') end
SWFTool command will be called when you save object.
With SWFTool you can use scripts for creating flash files. More on wiki.swftools.org/index.php/Swfc
flash_object = FlashTool::FlashScript.new("path_to_script") flash_object.save(output_file)
Other way
FlashTool::FlashScript.create("path_to_script","output_path")
It is possible to push flash data in variable
flash = FlashScript.flash_data("path_to_script")
or
flash_object = FlashTool::FlashScript.new("path_to_script") flash = flash_object.cgi
It is very simple
FlashTool::FlashTool.parse_text('path_to_file.swf')
You can get data from flash files with swfdump tool
FlashTool::FlashTool.swfdump('path_to_file.swf', 'command') #use swfdump options http://www.swftools.org/swfdump.html
Don’t use option text it is buggy, instead that use method FlashTool.parse_text With method swfdump output is string
Better way
FlashTool::FlashTool.(command) List of command can get from http://www.swftools.org/swfdump.html
Examples
FlashTool::FlashTool.rate(file) #return Float FlashTool::FlashTool.width(file) #return Integer FlashTool::FlashTool.height(file) #return Integer FlashTool::FlashTool.frames(file) #return Integer
Other methods returns String
All this methods call commands swfdump, every time you call method. If you want to do it in one pass use
FlashTool::FlashTool.flash_info(file)
Returns hash with keys ‘width’, ‘rate’, ‘height’, ‘frames’, and all values are strings
This is advance technique for combining flash files. It is possible to combine two or more flash files More about this on www.swftools.org/swfcombine.html For simple adding viewer use FlashObject and creating vith view method
flash = FlashCombine.new() do |f| f.master(inputs) f.slave("viewport",TEST_SWF) f.rate(25) f.output(output_file) f.save() end