3 Replies Latest reply: May 25, 2011 10:22 AM by The Feldkircher RSS

    Server site php and As3 data

    adii08

      Hi,

       

      I am new in php coding. I want to get image data from php and also display in flash.

      I want to know... how to read and display imagejpeg( $imgData ); from php.

       

      I am able to get php data in flash through below method...

       

      /* AS3 */------------------

       

      var src:String = "pic.jpg";

      var width:String = "250";

      var height:String = "250";

       

      var urlReq:URLRequest = new URLRequest(src);

      var urlLoader:URLLoader = new URLLoader();

       

      var urlVar:URLVariable = new URLVariable();

      urlVar.src= src;

       

      urlReq.mehtod = URLRequestMethod.POST;

      urlReq.data = urlVar;

       

      urlLoader.load ( urlReq );

      urlLoader.addEventListener(Event.Complete, doneProcFnc)

       

      function doneProcFnc(ev:Event):void{

            trace ( "data access from php done" );

      }

       

      ------------/*   */

       

      /* PHP */

       

      $src = $_POST [ 'src' ];

      $wd = $_POST [ ' width' ];

      $ht = $_POST [ ' height' ];

       

      /*  this function will create one black color area for croping refence */

      $cropImg = imagecreatetruecolor ( cropImageWd, cropImageHt );

       

      /* this function will reproduce particular image required width and height without reducing the image quality */

      imagecopyresampled ( cropImage , sourceImage, destX , destY, sourX, sourY, ect... );

       

       

      imagejpeg( $imgData ) ;

       

      ------------------/* */

       

      Now, here the problem comes. I don't know how to display that imagejpeg data into flash.


      I need help.

      Thanks.

        • 1. Re: Server site php and As3 data
          The Feldkircher Community Member

          Hi

           

          In PHP simply echo your image back to flash:

           

          echo imagejpeg($imgData);

           

          In flash:

           

          For images it's best to use the Loader class rather than the URLLoader which is better suited to text or XML.

           

          I think you'll find the loader class far easier for your project.

           

          Hope it helps

          • 2. Re: Server site php and As3 data
            adii08 Community Member

            Thanks.

             

            No.No.No. I am not loading image from folder.

             

            step1 : I m sending some image information to php (src , width , height)

            step2 : PHP code will take that information

            step3 : PHP code will crop that particular image (some calcution for quality)

            step4 : PHP code will generate some image data that is /* imagejpeg( $imgData ) */ and return back to flash

            step5 : Now the problem occur, how can i take that image data in flash or what form

             

            Possibilities :

             

            ? should i get image data as text format and it needs to be encoded (like jpeg encoder)

            ? i don't know i already try jpegencoder but i did not get anything

            ? ? ?

             

             

            var src:String = "pic.jpg";

            var width:String = "250";

            var height:String = "250";

             

            var urlReq:URLRequest = new URLRequest(src);

            var urlLoader:URLLoader = new URLLoader();

             

            var urlVar:URLVariable = new URLVariable();

            urlVar.src= src;

             

            urlReq.mehtod = URLRequestMethod.POST;

            urlReq.data = urlVar;

             

            urlLoader.load ( urlReq );

            urlLoader.addEventListener(Event.Complete, doneProcFnc)

             

            function doneProcFnc(ev:Event):void{

                

                      trace ( "data access from php done" + ev.target );

                    // imagejpeg( $imgData )

            }

             

            ------------/*   */

             

            /* PHP */

             

            $src = $_POST [ 'src' ];

            $wd = $_POST [ ' width' ];

            $ht = $_POST [ ' height' ];

             

            /*  this function will create one black color area for croping refence */

            $cropImg = imagecreatetruecolor ( cropImageWd, cropImageHt );

             

            /* this function will reproduce particular image required width and height without reducing the image quality */

            imagecopyresampled ( cropImage , sourceImage, destX , destY, sourX, sourY, ect... );

             

             

            imagejpeg( $imgData ) ;

            • 3. Re: Server site php and As3 data
              The Feldkircher Community Member

              OK

               

              I am still not sure why your sending an image reference from flash to php and back again.

              Why not use the BitMap Class within flash to do your image sizing. It's far easier and more reliable.

               

              Google 'AS3 BitMap Class'

               

              Hope it helps