downloads | documentation | faq | getting help | mailing lists | reporting bugs | sites | links | my 
search for in the  
view the version of this page
Last updated: Thu, 21 Aug 2003

LVIII. Ming functions for Flash


This extension is EXPERIMENTAL. The behaviour of this extension -- including the names of its functions and anything else documented about this extension -- may change without notice in a future release of PHP. Use this extension at your own risk.


First of all: Ming is not an acronym. Ming is an open-source (LGPL) library which allows you to create SWF ("Flash") format movies. Ming supports almost all of Flash 4's features, including: shapes, gradients, bitmaps (pngs and jpegs), morphs ("shape tweens"), text, buttons, actions, sprites ("movie clips"), streaming mp3, and color transforms --the only thing that's missing is sound events.

Note that all values specifying length, distance, size, etc. are in "twips", twenty units per pixel. That's pretty much arbitrary, though, since the player scales the movie to whatever pixel size is specified in the embed/object tag, or the entire frame if not embedded.

Ming offers a number of advantages over the existing PHP/libswf module. You can use Ming anywhere you can compile the code, whereas libswf is closed-source and only available for a few platforms, Windows not one of them. Ming provides some insulation from the mundane details of the SWF file format, wrapping the movie elements in PHP objects. Also, Ming is still being maintained; if there's a feature that you want to see, just let us know

Ming was added in PHP 4.0.5.


To use Ming with PHP, you first need to build and install the Ming library. Source code and installation instructions are available at the Ming home page: along with examples, a small tutorial, and the latest news.

Download the ming archive. Unpack the archive. Go in the Ming directory. make. make install.

This will build and install it into /usr/lib/, and copy ming.h into /usr/include/. Edit the PREFIX= line in the Makefile to change the installation directory.


Example 1. built into php (unix)

    mkdir <phpdir>/ext/ming
    cp php_ext/* <phpdir>/ext/ming
    cd <phpdir>
    ./configure --with-ming <other config options>


Build and install php as usual, restart web server if necessary.

Now either just add to your php.ini file, or put dl(''); at the head of all of your Ming scripts.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.




SWFBUTTON_UP (integer)

































Predefined Classes

The classes below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

Ming introduces 13 new objects in PHP, all with matching methods and attributes. To use them, you need to know about objects.














Table of Contents
ming_setcubicthreshold --  Set cubic threshold (?)
ming_setscale --  Set scale (?)
ming_useswfversion --  Use SWF version (?)
SWFAction -- Creates a new Action.
SWFBitmap->getHeight -- Returns the bitmap's height.
SWFBitmap->getWidth -- Returns the bitmap's width.
SWFBitmap -- Loads Bitmap object
swfbutton_keypress --  Returns the action flag for keyPress(char)
SWFbutton->addAction -- Adds an action
SWFbutton->addShape -- Adds a shape to a button
SWFbutton->setAction -- Sets the action
SWFbutton->setdown -- Alias for addShape(shape, SWFBUTTON_DOWN))
SWFbutton->setHit -- Alias for addShape(shape, SWFBUTTON_HIT)
SWFbutton->setOver -- Alias for addShape(shape, SWFBUTTON_OVER)
SWFbutton->setUp -- Alias for addShape(shape, SWFBUTTON_UP)
SWFbutton -- Creates a new Button.
SWFDisplayItem->addColor -- Adds the given color to this item's color transform.
SWFDisplayItem->move -- Moves object in relative coordinates.
SWFDisplayItem->moveTo -- Moves object in global coordinates.
SWFDisplayItem->multColor -- Multiplies the item's color transform.
SWFDisplayItem->remove -- Removes the object from the movie
SWFDisplayItem->Rotate -- Rotates in relative coordinates.
SWFDisplayItem->rotateTo -- Rotates the object in global coordinates.
SWFDisplayItem->scale -- Scales the object in relative coordinates.
SWFDisplayItem->scaleTo -- Scales the object in global coordinates.
SWFDisplayItem->setDepth -- Sets z-order
SWFDisplayItem->setName -- Sets the object's name
SWFDisplayItem->setRatio -- Sets the object's ratio.
SWFDisplayItem->skewX -- Sets the X-skew.
SWFDisplayItem->skewXTo -- Sets the X-skew.
SWFDisplayItem->skewY -- Sets the Y-skew.
SWFDisplayItem->skewYTo -- Sets the Y-skew.
SWFDisplayItem -- Creates a new displayitem object.
SWFFill->moveTo -- Moves fill origin
SWFFill->rotateTo -- Sets fill's rotation
SWFFill->scaleTo -- Sets fill's scale
SWFFill->skewXTo -- Sets fill x-skew
SWFFill->skewYTo -- Sets fill y-skew
SWFFill -- Loads SWFFill object
swffont->getwidth -- Returns the string's width
SWFFont -- Loads a font definition
SWFGradient->addEntry -- Adds an entry to the gradient list.
SWFGradient -- Creates a gradient object
SWFMorph->getshape1 -- Gets a handle to the starting shape
SWFMorph->getshape2 -- Gets a handle to the ending shape
SWFMorph -- Creates a new SWFMorph object.
SWFMovie->add -- Adds any type of data to a movie.
SWFMovie->nextframe -- Moves to the next frame of the animation.
SWFMovie->output -- Dumps your lovingly prepared movie out.
swfmovie->remove -- Removes the object instance from the display list.
SWFMovie->save -- Saves your movie in a file.
SWFMovie->setbackground -- Sets the background color.
SWFMovie->setdimension -- Sets the movie's width and height.
SWFMovie->setframes -- Sets the total number of frames in the animation.
SWFMovie->setrate -- Sets the animation's frame rate.
SWFMovie->streammp3 -- Streams a MP3 file.
SWFMovie -- Creates a new movie object, representing an SWF version 4 movie.
SWFShape->addFill -- Adds a solid fill to the shape.
SWFShape->drawCurve -- Draws a curve (relative).
SWFShape->drawCurveTo -- Draws a curve.
SWFShape->drawLine -- Draws a line (relative).
SWFShape->drawLineTo -- Draws a line.
SWFShape->movePen -- Moves the shape's pen (relative).
SWFShape->movePenTo -- Moves the shape's pen.
SWFShape->setLeftFill -- Sets left rasterizing color.
SWFShape->setLine -- Sets the shape's line style.
SWFShape->setRightFill -- Sets right rasterizing color.
SWFShape -- Creates a new shape object.
swfsprite->add -- Adds an object to a sprite
SWFSprite->nextframe -- Moves to the next frame of the animation.
SWFSprite->remove -- Removes an object to a sprite
SWFSprite->setframes -- Sets the total number of frames in the animation.
SWFSprite -- Creates a movie clip (a sprite)
SWFText->addString -- Draws a string
SWFText->getWidth -- Computes string's width
SWFText->moveTo -- Moves the pen
SWFText->setColor -- Sets the current font color
SWFText->setFont -- Sets the current font
SWFText->setHeight -- Sets the current font height
SWFText->setSpacing -- Sets the current font spacing
SWFText -- Creates a new SWFText object.
SWFTextField->addstring -- Concatenates the given string to the text field
SWFTextField->align -- Sets the text field alignment
SWFTextField->setbounds -- Sets the text field width and height
SWFTextField->setcolor -- Sets the color of the text field.
SWFTextField->setFont -- Sets the text field font
SWFTextField->setHeight -- Sets the font height of this text field font.
SWFTextField->setindentation -- Sets the indentation of the first line.
SWFTextField->setLeftMargin -- Sets the left margin width of the text field.
SWFTextField->setLineSpacing -- Sets the line spacing of the text field.
SWFTextField->setMargins -- Sets the margins width of the text field.
SWFTextField->setname -- Sets the variable name
SWFTextField->setrightMargin -- Sets the right margin width of the text field.
SWFTextField -- Creates a text field object

add a note add a note User Contributed Notes
Ming functions for Flash
php-page at mailfilter dot com dot ar
06-May-2003 10:35
About the last note, I forgot to tell I'm using the GNU make, also. I don't know if all of the above works well with the Solaris native make utility.
php-page at mailfilter dot com dot ar
06-May-2003 04:55
This is how I got MING compiled into PHP with Solaris 2.6/2.8:

First, I didn't use the latest version of Bison, which gave me many troubles. I started having the following already up and running:

* gtar-sparc.gz (from , just uncompress with gzip -d and copy to /usr/local/bin with 755 as permissions).
* Solaris cc compiler 4.2 (I don't have a gnu C with all the installed libraries).
* GNU C (I had to use GNU C anyway because MING itself doesn't compile with my version of Solaris C).

If you have a full-working gnu C, along with the libraries, ignore all the CC=cc settings in the following procedure.

These are the versions and products/libraries I used:


I used gtar to extract all the files:

gtar xzf apache_1.3.27.tar.gz
gtar xzf bison-1.28.tar.gz
gtar xzf flex-2.5.4a.tar.gz
gtar xzf m4-1.4.tar.gz
gtar xzf ming-0.2a.tgz
gtar xzf php-4.3.1.tar.gz

Next, Apache (you may not need all these options):

cd apache_1.3.27
Cc=cc ./configure --with-layout=Apache \
            --prefix=/u01/apache/server \
            --without-execstrip \
            --server-uid=nobody \
            --server-gid=nogroup \
            --disable-module=userdir \
            --enable-module=unique_id \
            --enable-module=expires \
            --enable-module=headers \
            --enable-module=include \
            --enable-module=info \
            --enable-module=status \

su (root password)
make install
cd ..

Next, bison:

cd bison-1.28
CC=cc ./configure
su (root password)
make install
cd ..

Next, m4:

cd m4-1.4
CC=cc ./configure
su (root password)
make install
cd ..

Next, flex:

cd flex-2.5.4a
CC=cc ./configure
su (root password)
make install
cd ..

Next, ming:

cd ming-0.2a
make static
mkdir lib include
cp libming.a lib/
cp ming.h include/
cd ..

Next, PHP (you may not need all these options):

cd php-4.3.1
CC=cc ./configure                    \
    --with-ming=/u01/apache/products/ming-0.2a/     \
    --with-apxs=/u01/apache/server/bin/apxs        \
    --enable-sigchild                \
    --enable-track-vars                \

su (root password)
make install

Got it.
gaz_b3 at yahoo dot com
04-Apr-2003 08:11
The current CVS version, Ming 0.3a, supports
a lot of MX ActionScript including the MX Drawing API.
This is very nice for easy command line compiling of
MX ActionScript only movies.

For example:

$movie = new SWFMovie();
$movie->setBackground(0xcc0xcc0xcc );

// mx actionscript
$strAction "
_root.createEmptyMovieClip ( 'triangle', 1 );
with ( _root.triangle ) {
lineStyle( 5, 0xff00ff, 100 );
moveTo( 200, 200 );
lineTo( 300,300 );
lineTo( 100, 300 );
lineTo( 200, 200 );

$movie->add(new SWFActionstr_replace("\r"""$strAction) ));

Lots of examples here:
dev at feth dot com
23-Sep-2002 03:59
You can find a Ming module for Apache( here:
20-Apr-2002 05:15
Like, the build instructions are for building from CVS, I think...

Mere mortals can just do:
cd ming-x.y.z  (xyz is version)
make static
make install
ldconfig  (you might need do use "whereis ldconfig" to find it, and then use the full path)
cd ../php-x.y.z
./configure --with-ming ...

And don't be copying the "new" ming code into your PHP dir like the ming instructions say to do.  That will just mess you up.
attila at linuks dot NOSPAM dot net
27-Dec-2001 01:42
You can get several .fdb font files from
kunnoichi at hotmail dot com
21-Aug-2001 02:50
//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

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->movie=new swfmovie ();
        $this->movie->setrate ($frame_rate);
    function convert_images($quality=80,$delete_old_files=1) {
        $main = opendir($this->path);
        //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)) {
                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);
                else $new_file_path=$file_path;
                //echo "Converted $filename to $new_file_path at quality $quality<br />";
    function make_movie() {
        $main = opendir($this->path);
        //Get all valid jpegs
        while($filename = readdir($main)) {
            if (ereg("(jpg|jpeg)\$",$filename)) {
        //Put jpegs in order
        //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);
            $this->movie->add(new swfbitmap($this->images[$a]));
            //echo "Added ".$valid_paths[$a]." to the movie<br />\n";
    function save_movie($file_name) {
    function output_movie() {
        header('Content-type: application/x-shockwave-flash');
ivv_rousse at yahoo dot com
04-Aug-2001 08:17
// Simple button with link


$s = new SWFShape();

// Set Font
$font = new SWFFont("test.fdb");
$text1 = new SWFText();
$b1 = new SWFButton();
$b1->addAction(new SWFAction("getURL('', 'phpsite');"),

$m = new SWFMovie();

$i $m->add($b1);

header("Content-type: application/x-shockwave-flash");

 Last updated: Thu, 21 Aug 2003
show source | credits | sitemap | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Sat 01 Nov 2003 04:13:36 EST EST