0 Replies Latest reply on Jun 15, 2011 7:45 AM by simonstlaurent

    GetBitmap - PHP - huh ? help !

    simonstlaurent

      Ok, for those of you who read my last post (Need information)  I'm still working on that customization module.  Thing is,

      I was requested new things during the developement process and I'm totally lost now.

       

      Not only I need to create the 'login' PHP files and test them on the server, I also need to create a module that will capture the image of the 'customized product' that the customer made and with a click, send it to us.

       

      I've found (from our earliest versions of our website (made by another developper)) a module in which I can have the customer upload a jpeg, png or bmp to the PHP and use this image over the initial image (contained in an empty MC), stretch and rotation tools included.

       

      Some forum told me I should create a byteArray and send the uploaded picture to the array then place it in a temporary MC over the product image.  I've found a module on the internet that captures the listed MCs at the 'press' event, in a pre-established frame.  But so far, all module sends the captured image to my printer.  I need to change that part.

       

      So, if ANYONE could just suggest something simpler....   like I said, I'm not developer yet, but I got some skills.  I can manage to get my things to work most of the time but this is totally new to me.  Never touched PHP before.

       

      Here's the code I've found for the upload of the image over the product :

       

       

      System.security.allowDomain("http://localhost/");
      import flash.net.FileReference;

      var listener:Object = new Object();

       

      listener.onSelect = function(selectedFile:FileReference):Void {
        statusArea.text = details.text = ""
        statusArea.text += "Attempting to upload " + selectedFile.name + "\n";
        selectedFile.upload("upload.php");
      };

       

      listener.onOpen = function(selectedFile:FileReference):Void {
        statusArea.text += "Uploading " + selectedFile.name + "\n";
      };

      listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
      imagePane.contentPath = "error";
      imagePane.content.errorMSG.text = "HTTPError number: "+httpError +"\nFile: "+ file.name;
      }

      listener.onIOError = function(file:FileReference):Void {
      imagePane.contentPath = "error";
      imagePane.content.errorMSG.text = "IOError: "+ file.name;
      }

      listener.onSecurityError = function(file:FileReference, errorString:String):Void {
      imagePane.contentPath = "error";
      imagePane.content.errorMSG.text = "SecurityError: "+SecurityError+"\nFile: "+ file.name;
      }

       

      listener.onComplete = function(selectedFile:FileReference):Void {
          statusArea.text += "Upload finished.\nNow downloading " + selectedFile.name + " to player\n";
          details.text = ""
        for(i in selectedFile) details.text +="<b>"+i+":</b> "+selectedFile[i]+"\n"
        downloadImage(selectedFile.name);
      };

      var imageFile:FileReference = new FileReference();
      imageFile.addListener(listener);

      uploadBtn.onPress = uploadImage;
      imagePane.addEventListener("complete", imageDownloaded);

      function uploadImage(event:Object):Void {
        imageFile.browse([{description: "Image Files", extension: "*.jpg;*.gif;*.png"}]);
      }

      function imageDownloaded(event:Object):Void {
        if(event.total == -1) {
          imagePane.contentPath = "error";
        }
      }

      function downloadImage(file:Object):Void {
        imagePane.contentPath =  "./files/" + file;
      }

      stop();

       

       

      This is the code for the jpeg to php:

       

      import flash.display.BitmapData;
      import flash.geom.Rectangle;
      import flash.geom.ColorTransform;
      import flash.geom.Matrix;
       
      class it.simontest.PrintScreen {
       
          public var addListener:Function
          public var broadcastMessage:Function
       
          private var id:   Number;
          public  var record:LoadVars;
       
          function PrintScreen(){
              AsBroadcaster.initialize( this );
          }
       
          public function print(mc:MovieClip, x:Number, y:Number, w:Number, h:Number){
              broadcastMessage("onStart", mc);
              if(x == undefined) x = 0;
              if(y == undefined) y = 0;
              if(w == undefined) w = mc._width;
              if(h == undefined) h = mc._height;
              var bmp:BitmapData = new BitmapData(w, h, false);
              record = new LoadVars();
              record.width  = w
              record.height = h
              record.cols   = 0
              record.rows   = 0
              var matrix = new Matrix();
              matrix.translate(-x, -y)
              bmp.draw(mc, matrix, new ColorTransform(), 1, new Rectangle(0, 0, w, h));
              id = setInterval(copysource, 5, this, mc, bmp);
          }
       
          private function copysource(scope, movie, bit){
              var pixel:Number
              var str_pixel:String
              scope.record["px" + scope.record.rows] = new Array();
              for(var a = 0; a < bit.width; a++){
                  pixel     = bit.getPixel(a, scope.record.rows)
                  str_pixel = pixel.toString(16)
                  if(pixel == 0xFFFFFF) str_pixel = "";  
                  scope.record["px" + scope.record.rows].push(str_pixel)
              }
              scope.broadcastMessage("onProgress", movie, scope.record.rows, bit.height)  
              scope.record.rows += 1
              if(scope.record.rows >= bit.height){
                  clearInterval(scope.id)
                  scope.broadcastMessage("onComplete", movie, scope.record)  
                  bit.dispose();
              }
          }
      }

       

       

       

      and this is the code for the FLA :

       

      import it.simontest.mloaderWindow

      import it.simontest.PrintScreen

       

       

      var loader:mloaderWindow = this.createClassObject(mloaderWindow, "loader", 10, {_x:-1000, _y:-1000})

      loader.setStyle("borderColor", 0xFFFFFF)

       

      var listener:Object = new Object();

       

      listener.onProgress = function(target:MovieClip, loaded:Number, total:Number){

          var perc = Math.round((loaded/total)*100)

          loader.label = "loading" + perc + "%"

          loader.value = perc

      }

      listener.onComplete = function(target:MovieClip, load_var:LoadVars){

          loader.label = "sending to php..."

          load_var.send("files/pixels.php", "_blank", "POST")

          loader.close()

      }

       

      function print_me(){

          video_mc.pause()  

          pn = new PrintScreen();

          pn.addListener( listener );

          pn.print(_root, 733, 9, 377, 469)

          loader.label = "computing... 0%"

          loader.open(true, true, true);

      }

       

       

      I won't place all of the codes I'm using I think you get the idea.  The print_me function needs to be replaced my 'send_me'  so we ask the PHP to send to our services the preview the customer has prepared for us on our email.  Then, we take care of building a nice looking preview image for them since we ask that they send us the logo itself in a PNG format or AI (to PDF).

       

      Anyway.... If ANYONE has an idea... a little guidance would be appreciated.  I can work these parts one by one.... but I don't have the knowledge YET to make all of them work together.

       

      Also, I'm downloaded active Perl and Strawberry Perl, hoping to emulate a PHP server.  I don't know which one to use...  any suggestions ?

       

      Thanks