Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating image through passing parameters to php 1

Status
Not open for further replies.

sdaver

Programmer
Feb 14, 2006
11
US
Friends,
Need help on this I am trying to pass information from flash to PHP and wish to create an image. following is the AS that I am using.

var listener:Object = new Object();
// copy in progress...
listener.onProgress = function(target:MovieClip, loaded:Number, total:Number){
var perc = Math.round((loaded/total)*100)
popup_mc.imgsavestatus_txt.text = "Capturing image... "+perc+"%";
//loader.label = "computing... " + perc + "%"
//loader.value = perc
}
// copy is complete, send the result LoadVars to PHP
listener.onComplete = function(target:MovieClip, load_var:LoadVars){
//loader.label = "sending to php..."
popup_mc.imgsavestatus_txt.text = "Sending data to server...";
//gServerData_lv.send("php_files/pixels.php", "_self", "_POST");
load_var.send("php_files/pixels.php", "_self", "POST");
popup_mc.imgsavestatus_txt.text = "";
popup_mc._visible=false;
//trace(load_var);
//loader.close()
}
/**
* Print Button has been clicked
*/
function print_me(print_mc:MovieClip){
popup_mc._visible=true;
print_mc=workArea_mc.selectedItem_mc;
//video_mc.pause() // first pause the playing video
var pn:printScreen = new PrintScreen(); // initialize the PrintScreen class
pn.addListener( listener ); // assign a listener
pn.print(print_mc,0,0,360,330); // copy the _root
//loader.label = "computing... 0%"
//loader.open(true, true, true); // open a loader
popup_mc.imgsavestatus_txt.text = "Capturing image... 0%";
}

The output displays garbage text....Yes GD2 lib is installed on the server, The PHP code that I am using is
as follows:
_________________________________________________

<?php
//error_reporting(0);
//print_r($HTTP_POST_VARS);
/**
* Get the width and height of the destination image
* from the POST variables and convert them into
* integer values
*/
//$w = (int)$_POST['width'];
//$h = (int)$_POST['height'];
$w = 360;
$h = 330;

// create the image with desired width and height

$img = imagecreatetruecolor($w, $h);

// now fill the image with blank color
// do you remember i wont pass the 0xFFFFFF pixels
// from flash?
imagefill($img, 0, 0, 0xFFFFFF);

$rows = 0;
$cols = 0;

// now process every POST variable which
// contains a pixel color
for($rows = 0; $rows < $h; $rows++){
// convert the string into an array of n elements
$c_row = explode(",", $_POST['px' . $rows]);
for($cols = 0; $cols < $w; $cols++){
// get the single pixel color value
$value = $c_row[$cols];
// if value is not empty (empty values are the blank pixels)
if($value != ""){
// get the hexadecimal string (must be 6 chars length)
// so add the missing chars if needed
$hex = $value;
while(strlen($hex) < 6){
$hex = "0" . $hex;
}
// convert value from HEX to RGB
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));
// allocate the new color
// N.B. teorically if a color was already allocated
// we dont need to allocate another time
// but this is only an example
$test = imagecolorallocate($img, $r, $g, $b);
// and paste that color into the image
// at the correct position
imagesetpixel($img, $cols, $rows, $test);
}
}
}

// print out the correct header to the browser
//header("Content-type:image/jpeg");
// display the image
imagejpeg($img, "", 90);
?>
----------------------------------------------------------

Thanks for the help in advance...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top