we can create a swf movie in at least 3 way
1) by adobe flash, created from *.fla
2) by flex create from *.mxml
3) and we can create *.swf file by a backend controller, say, php or perl.
We now focus on 3). All we want is the open source swf library, named "Ming". It's a api to create swf file.
Here is what I think it can be used for:
1) protect your private image, you want to hide the url of your image and don't want others to say it as a local image file:
$path = "my_movie_dir"; //relative path to the jpg/png or bmp files
$frame_rate=30; //frame rate of the flash movie
$quality=50; //image quality during conversion (only valid if not jpeg)
$skip_rate=5; //how many frames to skip
set_time_limit("600"); //this could take some time
$converter=new images_to_swf($path,$frame_rate,$skip_rate);
//$converter->convert_images(70); //Use this if using non jpeg files or decreasing the quality
$converter->make_movie();//Make the movie
//Do two things with it
$converter->save_movie("my_movie_dir/my_movie.swf");
$converter->output_movie();
class images_to_swf {
var $path; //path to the image files
var $skip_rate;
var $movie;
var $images=array();
function images_to_swf($path,$frame_rate=30,$skip_rate=5) {
$this->path=$path;
$this->skip_rate=$skip_rate;
$this->movie=new swfmovie ();
$this->movie->setrate ($frame_rate);
}
function convert_images($quality=80,$delete_old_files=1) {
$main = opendir($this->path);
rewinddir($main);
//first convert to jpeg (if we have to)
//also change the quality
while($filename = readdir($main)) {
//only use valid file types
if (ereg("(png|bmp|jpg|jpeg)\$",$filename)) {
$file_path=$this->path."/".$filename;
if (ereg("png\$",$filename)) $temp_img=imagecreatefrompng ($file_path);
else if (ereg("bmp\$",$filename)) $temp_img=imagecreatefrompng ($file_path);
else if (ereg("(jpg|jpeg)\$",$filename)) $temp_img=imagecreatefromjpeg ($file_path);
if (ereg("(png|bmp)\$",$filename)) {
if ($delete_old_files) unlink($file_path);
$new_file_path=$file_path.".jpg";
}
else $new_file_path=$file_path;
ImageJPEG($temp_img,$new_file_path,$quality);
//echo "Converted $filename to $new_file_path at quality $quality<br />";
}
}
}
function make_movie() {
$main = opendir($this->path);
rewinddir($main);
//Get all valid jpegs
while($filename = readdir($main)) {
if (ereg("(jpg|jpeg)\$",$filename)) {
$file_path=$this->path."/".$filename;
$valid_paths[]=$file_path;
}
}
//Put jpegs in order
sort($valid_paths);
//then create the movie
for ($a=0; $a<count($valid_paths); $a=$a+$this->skip_rate) {
$fp = fopen($valid_paths[$a],"rb");
$this->images[$a] = fread($fp,999999);
fclose($fp);
$this->movie->add(new swfbitmap($this->images[$a]));
$this->movie->nextframe();
//echo "Added ".$valid_paths[$a]." to the movie<br />\n";
}
}
function save_movie($file_name) {
$this->movie->save($file_name);
}
function output_movie() {
header('Content-type: application/x-shockwave-flash');
$this->movie->output();
}
2) construct a complex flash componet according to your backend database
More sample can be reached at: http://www.gazbming.com/