|
-
Senior Member
Another 'save as image' thread..
ok.. so I finally wanted to actually try instead of just reading it.. (ie: had a need for it)
I read the same basic threads/posts that go to the same tuts.. however I couldnt get things to work..
not sure if AS, PHP..or if a hosting problem possibly? (permissions)
long story short.. I am trying to get the most straight forward (no filters..no video capture..etc) method to work.
just a clip on stage.. has some scribbles or other movieClip attached inside fo it.. but whatever is inside tis 'containerClip' should be copied 7 sent to a php script to be made into an image..
AS:
PHP Code:
import flash.display.BitmapData;
button1.onPress = function(){ output(); }
function output() { var snap:BitmapData = new BitmapData(containerClip._width, containerClip._height, false, 0xFFFFFF); snap.draw(containerClip); var pixels:Array = new Array(); var w:Number = snap.width; var h:Number = snap.height; for (var a = 0; a<=w; a++) { for (var b = 0; b<=h; b++) { var tmp = snap.getPixel(a, b).toString(16); pixels.push(tmp); } } //send to php for image creation var output:LoadVars = new LoadVars(); output.img = pixels.toString(); output.height = h; output.width = w; output.send("http://www.domainname.com/folder/show.php", "output", "POST");
}
PHP:
PHP Code:
<?php $data = explode(",", $_POST['img']); $width = $_POST['width']; $height = $_POST['height']; $image=imagecreatetruecolor( $width ,$height ); $background = imagecolorallocate( $image ,0 , 0 , 0 ); //Copy pixels $i = 0; for($x=0; $x<=$width; $x++){ for($y=0; $y<=$height; $y++){ $int = hexdec($data[$i++]); $color = ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int); imagesetpixel ( $image , $x , $y , $color ); } } //Output image and clean header( "Content-type: image/jpeg" ); ImageJPEG( $image ); imagedestroy( $image ); ?>
I see it looks to be currently set-up for.jpg output.. I would eventually want it to be a .gif or .png.. so does that mean in the AS using getPixe32() instead? or is there other changes?
Thanks
sorry this is AS2.0 only (Flash 8)
this link:
http://www.quasimondo.com/archives/000572.php
source files are sorta working out of the box.. as I see the image being created.. however he is using a custom class with the file upload reference included..and Id like to have something just VERY simple and then move forward..
on click on button..take pre-determined containerClip (and all nested content).. send the data to php script on server,.. php script takes bitmap data/array creates a .png (or whatever at this point).. and then returns some message back to flash.. saying all is complete.. and maybe a url?
at this point.. thing will change.. but Id like to get here if anyone can help or offer suggestions? ultimately I guess id like for it to be emailed.. 
or just have it open in a new page?..
thanks
Last edited by whispers; 05-08-2008 at 04:46 PM.
-
Senior Member
-
Flashmatics
-
Flashmatics
-
Senior Member
Yeah I looked at that..thanks.. and I was looking for some help on DUMBING it down..
would like to NOT have it be an external class for first use with it..
also wanted to try and trim outt he PRINT stuff..etc..
just a basic bitMap copy/draw.. and pass the bitMap pixel data to a php script..
I want to break it down into 'steps'.. so I wcan work through it and add as I understand more.. like adding the file reference stuff, upload feedback..etc
Thanks
-
Senior Member
Hey Zain-
not sure if you're around..
anywho.. just getting back around to this...
so if anyone can help..please do.
try to break it down in simple steps and then build off it.. (NOT using anyone's external classes) 
so keeping with the initial sample code:
PHP Code:
import flash.display.BitmapData;
button1.onPress = function(){ output(); }
function output() { var snap:BitmapData = new BitmapData(containerClip._width, containerClip._height, false, 0xFFFFFF); snap.draw(containerClip); var pixels:Array = new Array(); var w:Number = snap.width; var h:Number = snap.height; for (var a = 0; a<=w; a++) { for (var b = 0; b<=h; b++) { var tmp = snap.getPixel(a, b).toString(16); pixels.push(tmp); } } //send to php for image creation var output:LoadVars = new LoadVars(); output.img = pixels.toString(); output.height = h; output.width = w; output.send("http://www.domainname.com/folder/show.php", "_blank", "POST");
}
seems fairly straight forward..
a function that makes a copy/snap shot of the pixel data in a specific clip (ie: 'containerClip' in this scenario)
I pass this bitMap data to the php script..that should just create an image in the same directory of the php script.. (or so this is my goal)
I know next to zero PHP.. so maybe the problem lies there?
PHP Code:
<?php $data = explode(",", $_POST['img']); $width = $_POST['width']; $height = $_POST['height']; $image=imagecreatetruecolor( $width ,$height ); $background = imagecolorallocate( $image ,0 , 0 , 0 ); //Copy pixels $i = 0; for($x=0; $x<=$width; $x++){ for($y=0; $y<=$height; $y++){ $int = hexdec($data[$i++]); $color = ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int); imagesetpixel ( $image , $x , $y , $color ); } } //Output image and clean header( "Content-type: image/jpeg" ); ImageJPEG( $image ); imagedestroy( $image ); ?>
when I test.. I get a huge HANG (testing through IDE).. like its trying to pass a bunch of data or something.. it finally becomes responsive again, however.. there is never any image created??
I dont believe this to be a permission fo host problem.. as testing the default (after I scribble a little in the focus clip to be exported) from:
http://www.quasimondo.com
DOES in fact create an image.. there are some other errors as well.. this has a saving percentage too I believe (or maybe an UPLOAD percentage form using a FileReference() instance?)
anyways.. any help is appreciated thanks
Last edited by whispers; 05-19-2008 at 05:18 PM.
-
Senior Member
latest attempt cleaned up some:
PHP Code:
import flash.display.BitmapData;
button1.onPress = function(){ trace("WIDTH CHECK 1 : "+containerClip._width); savePic(containerClip); }
function savePic(mc:MovieClip) { var snapShot:BitmapData = new BitmapData(mc._width, mc._height, false, 0xFFFFFF); trace("WIDTH CHECK 3 : "+mc._width); snapShot.draw(containerClip); var pixels:Array = new Array(); var w:Number = snapShot.width; var h:Number = snapShot.height; for (var a = 0; a<=w; a++) { for (var b = 0; b<=h; b++) { var tmp = snapShot.getPixel(a, b).toString(16); pixels.push(tmp); } } //send to php for image creation var output:LoadVars = new LoadVars(); /* output.onLoad = function(success){ if(!success){ trace("PHP NOT FOUND"); }else{ trace("PHP SCRIPT FOUND"); } } */ output.img = pixels.toString(); output.height = h; output.width = w; output.send("http://www.dmstudios.net/demos/makepic/makePic2.php", "_blank", "POST");
}
If someone could tell me if its a AS side or PHP side problem..even that would help me to narrow down my search.. 
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|