PDA

View Full Version : Flash Send/Load



jimjiminyjimjim
May 17th, 2007, 11:17 AM
I'm using Sephiroths print screen code. Everything works fine except I want mine to behave slightly diffently.

In his example when the PHP is called a new window is opened and the image is displayed. I would like the file to write to disk in the background with no new window opening.

I have got the PHP file to write to the server but the new window still opens. I'm guessing its something to do with this actionscript:



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


What is the best way for the php to happen in the background?

Heres the php in case that affects it.



<?php

error_reporting(0);
/**
* 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'];

// 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, "imagetest.jpg", 90);

?>

borrob
May 17th, 2007, 12:01 PM
load_var.send("pixels.php","_blank","POST")

instead use

load_var.send("pixels.php","_self","POST")

jimjiminyjimjim
May 17th, 2007, 01:18 PM
load_var.send("pixels.php","_self","POST")[/QUOTE]


That just replaces the flash movie in the browser window with the result of the php. Is there no way to have the PHP run in the background. Previously I have used SendAndLoad with Loadvars and these have been passed from and too flash in the background. I was hoping I could do something similar.

joran420
May 17th, 2007, 03:01 PM
loadvar.sendAndLoad("xxx.php","post")

jimjiminyjimjim
May 17th, 2007, 05:47 PM
Well that gets rid of the popup window but the PHP script no longer executes correctly. Its meant to write a jpeg file to the webserver but it doesn't.

Is there something else I can try?

Alternatively as a work around (but not ideal) is it possible to change the size of the popup window? And also get PHP to close it once it has executed the script?

GOLDfish_74
May 17th, 2007, 06:40 PM
Alternatively as a work around (but not ideal) is it possible to change the size of the popup window? And also get PHP to close it once it has executed the script?



<body>
<script language="javascript">
var winW = WIDTH, winH = HEIGHT;
if (parseInt(navigator.appVersion)>3) {
if (navigator.appName=="Netscape") {
winW = window.innerWidth;
winH = window.innerHeight;
}
if (navigator.appName.indexOf("Microsoft")!=-1) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
}
document.write(
"Window width = "+winW+"<br>"
+"Window height = "+winH
)
</script>

That will make the window the desired size.
I don't know if this would work to close your window, but you could try:


<script language="javascript">
window.close();
</script>

joran420
May 17th, 2007, 06:52 PM
you can probably tweak the PHP to work with the silent sendAndLoad....post your php file

[edit] errrr
header("Content-type:image/jpeg");
// display the image
imagejpeg($img, "imagetest.jpg", 90);

[/code]
thats why its not working.... you are setting it as a image header....
you need to use the GD image library to create the image..

jimjiminyjimjim
May 17th, 2007, 06:57 PM
Heres the entire PHP code. Its from Sephiroths print screen/export jpeg.




<?php

error_reporting(0);
/**
* 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'];

// 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, "imagetest.jpg", 90);

?>

Digitalosophy
May 17th, 2007, 07:01 PM
just send imagetest.jpg back to flash as a variable and use loadMovie(); to load it.

jimjiminyjimjim
May 17th, 2007, 07:07 PM
I don't want the jpeg to load in flash - well not at this point in the code anyway!

Sorry only just saw your post Joran - how do I use the GD image library to create the jpeg?

joran420
May 17th, 2007, 09:23 PM
http://www.phptutorial.info/learn/create_images/

thats a good pointer to get started thats creating an image from scratch you will have the image data already but hopefully that points you in the right direction....

jimjiminyjimjim
May 17th, 2007, 09:38 PM
Sorry to keep bugging you with this one!

I had a quick read of the tutorial. I'm not particularly strong on PHP. (hence the problems!!)
I don't really understand what the difference is between what my PHP script does and what the tutorials do. The only difference I could see was the header information that was pointed out.

So I tried removing the header code and it still didn't work. As I understood it - that part was basically so the browser rendered it as a jpeg and didn't show a load of data characters. I don't really understand which other parts of the php needs changing as the tutorials and other sites always deal with situations where the resulting image is displayed in a browser window.

joran420
May 17th, 2007, 10:13 PM
can you post a zip with all your files and ill see if i cant patch up your php for ya :P

jimjiminyjimjim
May 18th, 2007, 06:42 AM
That would be awesome. Thanks very much for all your help. Here are the files:

http://www.jamesrhodes.co.uk/images/noteboard.zip

:sure:

joran420
May 18th, 2007, 11:40 AM
no problem ill take a look when i get home from work tonight :)

jimjiminyjimjim
May 19th, 2007, 05:59 AM
Hi Joran, did you have any joy with this one? :)

joran420
May 19th, 2007, 02:09 PM
heh sorry i forgot looking now :P

joran420
May 19th, 2007, 02:34 PM
ummm noteboardread.php isnt in the zip ... pixesls.php is but the fla keeps refering to this other php

well i found the send command...but cant figure out where in your fla the trigger is...

jimjiminyjimjim
May 19th, 2007, 06:14 PM
I've re-uploaded the files should have all the php in there:

http://www.jamesrhodes.co.uk/images/noteboard.zip

I'll try and talk you through it as best I can.

Basically when someone creates a note by dragging a pin onto the note on the board a function called pindata() is called. This is found on the layer called pindata. Within this function two other functions are called - print_me() which is found in the bitmap ren layer and notedata() which is also found in the pindata layer.

The notedata() function calls the newnotice.php which basically just records the x and y coordinates of the note and the coordinates and colour of the pin.These are then passed to a MySQl database. A timecode is also generated which is used to name the jpeg that is the result of the next function.

The function print_me() is the bitmap rendering function that calls the pixel.php file that I am having problem with. It is found on the bitmap ren layer. This basically passes the bitmap information to the php script which renders a bitmap and saves it to my web server. However, in doing so at the moment a blank window opens up which is what I would like to get rid of.

There is also a noteboardread.php which is used for the drawing of the noteboard when it first loads. It basically creates notes from the rendered bitmaps and the coordinates that have been saved. All the script for that is on the draw board layer but I don't think this is relevent to the project. Also included is a folder with the Sephrioth classes for rendering the bit map.

Thats about it!!!! I hope this helps. As I said before I really appreciate you looking into this. Thanks.

joran420
May 19th, 2007, 07:39 PM
lol ok well i created a database that matched your variables....but that php isnt even adding to the DB so i musta messed up something can you export you data base and post the sql here? or PM it to me? (in phpmyadmin go to your "noticebord" table and select the export tab from the top and hit go and copy/paste the sql.... and anyother db's i might need..

joran420
May 19th, 2007, 07:51 PM
lol nm i just had to direct it to my local host...your image is already stored in your db table.. you dont really need to write an actual image file

ill give you some php to retrieve the image as an image from the database when your ready to display it...or if you really want to save it as an image i can help with that too...
[edit] lol i lied image is a link to a filename...

http://joranbeasley.net/FK/sendAndLoad.zip

there ya go...make sure the folder its in has permission set to allow annomouse file uploads(i think it needs CHMOD 777 ) so you might not want to write to the same directory as the php and stuff ;P

jimjiminyjimjim
May 19th, 2007, 09:51 PM
Thats awesome. Thanks very much for sorting it out for. Much appreciated. :}

robin_havoc
March 26th, 2008, 03:52 AM
hey jimjiminyjimjim,
i am having the similar issue but the file at http://joranbeasley.net/FK/sendAndLoad.zip is not available yet.
can u tell me the solution how the pixel.php file was not been call or loaded....

waiting for you reply...