<?php include("sample_utils.php"); // provides some utils and using mk $imageFN = "85569310_beac638d2f.jpg"; // source image file name $bm = new Bitmap_item(); // mk bitmap item class $bmTag = $bm->create_from_file($imageFN); // create swf tag from file $bitmapWidth = $bm->get_bitmapWidth(); // $bitmapHeight = $bm->get_bitmapHeight(); // width, height of image $mad["x"] = 150; // ... array is used ... $mad["y"] = 20; // ... to place bitmap $mad["width"] = $bitmapWidth; // ... properly $mad["height"] = $bitmapHeight; // $shape1 = new MKshape_container("", 2); // the shape that will wrap bitmap // add a bitmap fill, there are some kind // for a single bounded image use CLIPPED_BITMAP_FILL // the last parameter will place the bitmap in the desired position // note that in this case we set position for bitmap, not for shape itself $shape1->add_bitmap_fill(1, CLIPPED_BITMAP_FILL, $mad); $shape1->add_rect($mad["x"], $mad["y"], $mad["width"], $mad["height"]); // image bounding box $shapeTD1 = $shape1->update_tagData(); // get shape tag $shapePB1 = $shape1->update_place_tagData(); $swf = new MKswf("bitmap.swf"); // start a fresh swf $swf->set_swfDir(SERVER_MKTMP); // change default working dir $swf->set_backgroundColor("#FF9933"); // change background color $swf->add_tagData($bmTag); // populate with image $swf->add_tagData($shapeTD1); // populate with shape wrapper $swf->add_tagData($shapePB1); // place on stage $swf->swf_output(); // save to disk $swfHeader = $swf->fetch_assoc(); $str = "<br />" .render_swf_box($swfHeader, $imgDir, false, false, true); $str .= "<br/><br/><strong>bitmap.swf created in " .SERVER_MKTMP ."</strong>"; ?>
there are some issues to consider when including image in an swf. Flash supports various bitmap type combined in different behaviour, e.g. lossy or lossless image, 8, 15, 24 bit/pixel and alpha channel stored with lossy o lossless bitmap.
Mk try to manage all bitmap type, betting the best way to store data. If you load a png with transparency mk will preserve alpha channel. Jpegs does not support alpha channel, so if you are going to include a lossy image + alpha channel you must deal with Bitmap_item by some of its methods, first create_from_file, and then create_alpha_from_file, picking data from a separate bitmap (grayscaled png is preferable).
Mk can also manage jpeg quality, see the reference.
Note that I used a shape container with add_rect to bound image, but you may prefer what shape you want, e.g. circle/ellipse or a weirdest amoeba contour.
Some words about bitmap fill
Flash supports some bitmap fill type, clipped and its variant clipped non-smoothed are the most used in swf, because they give their typical look (a simple image that you can view by any image viewer), but there are some nice variation, such repeating and repeating non-smoothed tiled image, so useful in games.
Using mk you can load images as tiled background, flash 8 now support this features also at runt-time, but earlier version does not.
Combining alpha channel with tiled image you may reach unexplored result without modifying your web application, simply updating the source file name.
![]()