sample #05
image with alpha channel
  1. <?php
  2. include("sample_utils.php"); // provides some utils and using mk
  3.  
  4. $swfFN = "sample03.swf"; // swf to read
  5. $mksi = new MKswf_inspector($swfFN); // instantiate sww inspector
  6. $mt = $mksi->fetch_assoc(); // get some data
  7. $fl = $mksi->get_frameList(); // get frames list
  8. $sca = new MKswf_serializer($mt, $fl); // serialize
  9. $mkim = new MKswf_item_grabber($swfFN, 1, IMAGE_ITEM); // grab image items
  10.  
  11. $bmList = $mkim->get_itemList(); // get items (images) list
  12.  
  13. // html publishing
  14. $tbl = new MKtable(); // new table object
  15. $tRow = array(); // an array
  16.  
  17. foreach($bmList as $bm){ // iterate over images list
  18. $bm->save_image(); // save image
  19. $tRow[0] = array(); // each item of this array correspond to a cell
  20. $ifn = $bm->get_imageFileName(); // get image file name
  21.  
  22. $str = "<img src=\"" .$imgDir; // wrap into an img html tag
  23. $str .= $ifn ."\" /><br />"; // build image path
  24. $str .= $ifn; // ...
  25. $tRow[0]["cellContent"] = $str; // fill cell
  26. $tbl->add_row($tRow); // add row to table
  27.  
  28. if($bm->hasAlpha()){ // if image contain alpha data
  29. $tRow[0] = array(); // ... create new row
  30. $bm->save_alpha(); // save alpha data
  31. $aifn = $bm->get_alphaImageFileName(); // get assigned file name to alpha data
  32.  
  33. $str = "<img src=\"" .$imgDir; // wraps into an img html tag
  34. $str .= $aifn ."\" /><br />"; // ...
  35. $str .= "alpha channel: " .$aifn; // ...
  36. $tRow[0]["cellContent"] = $str; // fill cell
  37. $tbl->add_row($tRow); // add row to table
  38. }
  39. }
  40.  
  41. // publish data in a table html tag + comment
  42. $str = trace_var($tbl->fetch_html(), "<strong>images saved in: " .SERVER_MKTMP ."</strong>", false, false, true);
  43. echo show_content($str, basename(__FILE__));
  44. ?>
in sample03.swf there is only one image lossy compressed with alpha, note that it is saved a png in anyway to hold alpha channel.
Alpha channel can be saved in a separate file.
MK uses gd for image manipulation, hope in future php will embrace powerful image library such image magick or gd gets substantial improvements e.g. alpha channel, resampling, resource handling etc. mikrokosmos