4 Replies Latest reply on Jan 6, 2009 1:38 PM by run,ryan!

    Display run-time image(PHP GD lib) in flex

    run,ryan! Level 3
      I want to use flex to show pictures which are generated by PHP GD libs ('Content-Type', 'image/png') via web service.
      the web service returned the images successfully , but I don't know how I can show these pictures in flex, as they are not like normal pictures which have URI with them. Dose anybody know how to show them or embed them?? Thanks.
        • 1. Re: Display run-time image(PHP GD lib) in flex
          *gsb* Level 1
          I do this often.
          The source of the image is the PHP script and its "GET" variables, if any.
          Here is a simple one for generating 'captcha' security images:

          <mx:Image id="captcha" source=" http://www......CaptchaSecurityImages.php"
          width="100" height="40" rotation="33" top="36" left="54" />



          • 2. Re: Display run-time image(PHP GD lib) in flex
            run,ryan! Level 3
            Thanks gsb.
            Unfortunately, we are calling a web service using "post" method only, and that web service is only accepting a JSON string as parameters.
            I can get the resultEvent.result.toString(), and I can see something beginning with PNG there, but I don't know how to display that. If I convert the string to byteArray via Base64Decoder, it will say
            Error: A partial block (3 of 4 bytes) was dropped. Decoded data is probably truncated!
            • 3. Re: Display run-time image(PHP GD lib) in flex
              yoav@cyteam.com
              A simple way would be to handle this on your server side (if you can).
              Add a PHP like showImage.php or something that is accessible via URL.
              This PHP file can directly access the image data or via your web Services get it.
              Here is a simple PHP example which gets the image data from a file ..:
              <?php
              /**
              * simple jpeg imagefile output
              */
              require_once(dirname(__FILE__) ."/../config.php");
              if(isset($_GET['imagefile'])) {
              $imagefile=$_GET['imagefile'];

              $file_path = $IMAGES_DIR;
              $imageFilePath = $file_path."/".$imagefile;
              //read jpeg image
              $image = file_get_contents($imageFilePath );
              if($image ){
              header('content-type: image/jpeg');
              echo $image;
              }

              }
              ?>
              Then in Flex code just use
              <mx:Image id="imageShow" source=" http://<your host specific accessible URL>showImage.php?imagefile='.$imageRef" ..

              or something similar to this ..
              • 4. Re: Display run-time image(PHP GD lib) in flex
                run,ryan! Level 3
                Thanks, I figured out a way to do that:
                use URLRequest to get the data of the image and use Loader to load the image. I tried HTTPService before but failed, because HTTPService can not handle binary stream well.