media @ VU
[] readme course preface I 1 2 II 3 4 III 5 6 7 IV 8 9 10 V 11 12 afterthoughts appendix references examples resources _

talk show tell print

flex-paint.php



  <?php
  //
  //techniques for exporting jpeg with PHP used from Sephirith's tutorial at www.sephiroth.it/tutorials/flashPHP/print_screen/page002.php
  //
  //get our width and height in integers from the post values
  width = (int)_POST['width'];
  height = (int)_POST['height'];
  data = _POST['data'];
  //begin our image
  temp_img = imagecreatetruecolor(width, height);
  //fill in white space
  imagefill(temp_img, 0, 0, 0xFFFFFF);
  
  rows = 0;
  cols = 0;
  data_row = explode("|", data);
  //replace data with color values
  for(rows = 0; rows < height; rows++){
      c_row = explode(",", data_row[rows]);
      for(cols = 0; cols < width; cols++){
          value = c_row[cols];
          if(value != ""){
              hex = value;
              while(strlen(hex) < 6){
                  hex = "0" . hex;
              }
              r = hexdec(substr(hex, 0, 2));
              g = hexdec(substr(hex, 2, 2));
              b = hexdec(substr(hex, 4, 2));
              test = imagecolorallocate(temp_img, r, g, b);
              imagesetpixel(temp_img, cols, rows, test);
          }
      }
  }
  //output to jpg and prompt download
  header("Content-Type: image/jpeg");
  header("Content-Disposition: attachment; filename=tmp/image_save.jpg");
  imagejpeg(temp_img, "", 100);
  ?> 
  


(C) A. Eliëns 21/5/2007

You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.