note 14904 added to ref.ming.php

From: Date: Mon, 20 Aug 2001 16:50:31 +0000
Subject: note 14904 added to ref.ming.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-16919@lists.php.net to get a copy of this message
//In quicktime, movies may be exported as jpeg or png //This object will convert any movie that has been saved as a group of images into //an swf file. The frame rate and other attributes can be controlled $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(); } } http://www.php.net/manual/en/ref.ming.php

« previous php.notes (#16919) next »