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