Create a swf slideshow : Ming functions for Flash : Functions PHP Source Code


PHP Source Code » Functions » Ming functions for Flash »

 

Create a swf slideshow


grab jpgs from specified directories and create a swf slideshow...

jpg slideshow


<?
/********************************************************************************
* @ File: slideshow.php
* @ Original date: October 2003 @ www16.brinkster.com/gazb/ming/
* @ Version: 2.0
* @ Summary:  grab jpgs from folders and create a swf slideshow
* @ Updated:  small improvements and summary text
* @ Copyright (c) 2003-2007, www.gazbming.com - all rights reserved.
* @ Author: gazb.ming [[@]] gmail.com - www.gazbming.com 
* @ Released under GNU Lesser General Public License - http://www.gnu.org/licenses/lgpl.html
********************************************************************************/

// just put the directories with the jpgs here and compile
$pathtojpgs= array();
$pathtojpgs[0]= "./";
//$pathtojpgs[1]= "C:/ming/jpgs/";
//$pathtojpgs[2]= "../mingwin/";
//$pathtojpgs[3]= "/usr/share/Eterm/pix/tile/";
//$pathtojpgs[4]= "./pics/";

// some typical movie variables
Ming_setScale(20.0000000);
ming_useswfversion(6);
$movie=new SWFMovie();
$movie->setBackground(rand(0,0xFF),rand(0,0xFF),rand(0,0xFF));
$movie->setRate(31); 
$movie->setDimension(550,400);

//// easing equation converted to php from Actionscript @ 
// http://www.robertpenner.com/easing_equations.as
// use of which are subject to the license @
// http://www.robertpenner.com/easing_terms_of_use.html
function easeInQuad ($t$b$c$d) {
$t/=$d;
    return 
$c*$t*$t $b;
};
function 
easeOutQuad ($t$b$c$d) {
$t/=$d;
    return -
$c *($t)*($t-2) + $b;
};

// basic actionscript control of playback using mouse
$strAction="
if(!init){
    init=true;
    stopped=false;
    controls = {
        onMouseDown: function () {
            if(!stopped){
                stop();
                stopped=true;
            }else{
                play();
                stopped=false;
            }
        }
    };
    Mouse.addListener(controls);
}
"
;
$movie->add(new SWFAction($strAction));

// grab the jpgs
$f = array();
for(
$i=0;$i<count($pathtojpgs);$i++){
    
$f[$i] = array();
    if (
$handle opendir($pathtojpgs[$i])) {
        while (
false !== ($file readdir($handle))) { 
            
$tmp explode(".",$file);
            if(
$tmp[1]=="jpg"){
                
array_push ($f[$i],$pathtojpgs[$i] . $file);
            }
        }
    }
}
closedir($handle);




///////////////slideshow patch start//////////////////////////////
// sort the jpgs into 'natural' order using natsort        //
// (eg 1.jpg,a.jpg,b1.jpg,b2.jpg,b10.jpg,b12.jpg,b100.jpg)    //
// see www.php.net Array docs for alts to natsort        //
for($i=0;$i<count($f);$i++){                    //
// echo "original order\n";                    //
// print_r($f[0]);                        //
                                //
natsort($f[$i]);     // sort that array            //
$tmp=implode(",",$f[$i]); // ugly...                //
$f[$i]=explode(",",$tmp); // but it works            //
                                //
// echo "new order\n";                        //
// print_r($f[0]);                        //
}                                //
///////////////slideshow patch end////////////////////////////////



// add the jpgs to the movie with basic fade in/out
$movie->nextFrame();
for(
$i=0;$i<count($f);$i++){
    for(
$k=0;$k<count($f[$i]);$k++){
        
$img = new SWFBitmap(fopen($f[$i][$k],"rb"));
        
$pic=$movie->add($img); 
        
$pic->moveTo( (275-$img->getwidth()/2),(200-$img->getheight()/2));
        
$transition=20;
$cnt=1$startpos=0$offset=1$duration=$transition;
while(
$cnt<=$duration){
$inc=easeInQuad ($cnt++, $startpos$offset$duration);
            
$pic->multColor(1,1,1,$inc);
            
$movie->nextFrame();
        }
        for(
$j=1;$j<=$transition*2;$j++){
            
$movie->nextFrame();
        }
$cnt=1$startpos=1$offset=-1$duration=$transition;
while(
$cnt<=$duration){
$inc=easeOutQuad ($cnt++, $startpos$offset$duration);
            
$pic->multColor(1,1,1,$inc);
            
$movie->nextFrame();
        }
        
$movie->remove($pic);
    }
}
$movie->nextFrame();

// save swf with same name as filename
$swfname basename(__FILE__,".php");
$movie->save("$swfname.swf",9);
?>


HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Functions
» Ming functions for Flash