1 Reply Latest reply on Apr 27, 2006 9:25 AM by blemmo

    flash to JPG / Php big problem

    raffael3d
      it seems many people have the same problem, but no really a solution.

      look at this image: on the right side is the original (black and white that's the way it should be), after the conversion it looks like the one on the left:
      http://www.raffael3d.com/konvert.jpg

      so it's rather blue, and data seems lost...

      why is this??

      what I do in PHP is:


      $data = explode(",", $_POST['img']);
      $width = $_POST['width'];
      $height = $_POST['height'];
      //Allocate image
      $image=(function_exists("imagecreatetruecolor"))?imagecreatetruecolor( $width ,$height ):imagecreate( $width ,$height );
      imagefill($image, 0, 0, 0xFFFFFF);
      //Copy pixels
      $i = 0;
      for($x=0; $x<=$width; $x++){
      for($y=0; $y<=$height; $y++){
      while(strlen($data[$i]) < 6) $data[$i] = "0" . $data[$i];
      $r = 255-hexdec("0X".substr( $data[$i] , 0 , 2 ));
      $g = 255-hexdec("0x".substr( $data[$i] , 2 , 2 ));
      $b = 255-hexdec("0x".substr( $data[$i++] , 4 , 2 ));
      $color = ($r << 16) | ($g << 8) | $b;
      $color = imagecolorallocate($image, $r, $g, $b);
      imagesetpixel ( $image , $x , $y , $color );
      }
      }
        • 1. Re: flash to JPG / Php big problem
          blemmo Level 1
          quote:

          $r = 255-hexdec("0X".substr( $data[$i] , 0 , 2 ));
          $g = 255-hexdec("0x".substr( $data[$i] , 2 , 2 ));
          $b = 255-hexdec("0x".substr( $data[$i++] , 4 , 2 ));
          $color = ($r << 16) | ($g << 8) | $b;
          $color = imagecolorallocate($image, $r, $g, $b);
          imagesetpixel ( $image , $x , $y , $color );

          I think there's something wrong with the last 3 lines: first, $color is set to a RGB value, and then it gets overwritten with the value returned by imagecolorallocate, which uses different values as parameter. I'm not sure about this, but I guess it should be something like
          $color = imagecolorallocate($image, $r << 16, $g << 8, $b);
          to get the color from the converted RGB values.

          hth,
          blemmo