Posted By

gfazioli on 04/03/08


Tagged

php jpg library save FlashGD


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

gokhankurt
Wiederkehr
gfazioli
robobobo
farrellj
THEPWN3R


Save JPG image from Flash CS3


 / Published in: ActionScript 3
 

URL: http://www.undolog.com/2008/03/31/come-salvare-immagini-in-flash-cs3/

This snipped is split in two sections: Actionescript 3 and PHP

  1. /**
  2. ** @prototype : 0.0.1
  3. ** @author : =undo=
  4. ** @email : [email protected]
  5. ** @web : http://www.undolog.com
  6. **
  7. ** @params :
  8. **
  9. ** __bitmap : puntatore alla nostra bitmap
  10. ** __width : larghezza in pixel
  11. ** __height : altezza in pixel
  12. **
  13. */
  14. // copia per la lettura - questo potrebbe essere evitato
  15. var sbmp:BitmapData = new BitmapData(__width, __height);
  16. sbmp.draw ( __bitmap );
  17. //
  18. var pixels:Array = new Array();
  19. for (var xx:uint = 0; xx <= __width; xx++) {
  20. for (var yy:uint = 0; yy <= __height; yy++) {
  21. pixels.push( sbmp.getPixel32(xx, yy).toString(16) );
  22. }
  23. }
  24. //
  25. var urlreq:URLRequest = new URLRequest( "http://miodominio.com/savebitmap.php" );
  26. var urlpar:URLVariables = new URLVariables();
  27. var urlldr:URLLoader = new URLLoader();
  28. //
  29. urlldr.addEventListener( Event.COMPLETE,
  30. function (e:Event):void {
  31. trace( ' Completato' );
  32. }
  33. );
  34. //
  35. urlpar.pixels = pixels.toString();
  36. urlpar.height = __height;
  37. urlpar.width = __width;
  38. urlreq.data = urlpar;
  39. urlreq.method = URLRequestMethod.POST;
  40. urlldr.load( urlreq );
  41.  
  42.  
  43. --- PHP ---
  44.  
  45. /**
  46. ** @prototype : 0.0.1
  47. ** @author : =undo=
  48. ** @email : [email protected]
  49. ** @web : http://www.undolog.com
  50. **
  51. ** @params :
  52. **
  53. ** __bitmap : puntatore alla nostra bitmap
  54. ** __width : larghezza in pixel
  55. ** __height : altezza in pixel
  56. **
  57. */
  58. // $pixels diventa un array con i valori dei singoli pixel
  59. $pixels = explode(",", $_POST['pixels']);
  60. $width = $_POST['width'];
  61. $height = $_POST['height'];
  62. // creo l'immagine - @evitando di emettere errori
  63. $image = @imagecreatetruecolor( $width ,$height );
  64. // Scrivo i pixel per tutta la lunghezza e altezza
  65. $index = 0;
  66. for($x=0; $x<=$width; $x++){
  67. for($y=0; $y<=$height; $y++){
  68. $r = hexdec("0x".substr( $pixels[$index] , 2 , 2 ));
  69. $g = hexdec("0x".substr( $pixels[$index] , 4 , 2 ));
  70. $b = hexdec("0x".substr( $pixels[$index] , 6 , 2 ));
  71. $color = imagecolorallocate($image, $r, $g, $b);
  72. imagesetpixel ($image,$x,$y,$color);
  73. $index++;
  74. }
  75. }
  76. // scrivo immagine (in JPG - ma potete usare un diverso formato) sul disco/server
  77. imagejpeg( $image, "immagine.jpg" );
  78. imagedestroy( $image ); // libero tutto

Report this snippet  

You need to login to post a comment.