Even if this article might seem to be a bit anachronistic - believe it or not - there are many people out there who still have to code in Actionscript 2.0 and who publish for Flash Player 8. And it looks like there are more and more projects where there is a requirement to save users' drawings, compositions or webcam snapshots to a server in order to add them to galleries, mail them to friends or simply download them.

Since the number of inquiries for commercial licenses of my BitmapExporter class has increased considerably I've decided to revise the code once more. The new version has been optimized in several places so the overall performance should be remarkably better. It also turned out that some encoding optimizations that I had used seemed to create compatibility issues with Asian operating systems. (Patrick - I should have listened to you earlier ;-) ...)

Here is a demo that allows you to play with different image types and the various settings that BitmapExporter offers:

The main features of BitmapExporter are:
- send any BitmapData object to a PHP server-side script with one line of code (currently alpha channels are ignored for performance reasons)
- if you only need PNG or BMP files a plain PHP installation is sufficient
- for JPEG support you will need a PHP installation with GD compiled in - this usually comes with the default package anyway
- option to automatically popup a download window for the user after the upload has been completed
- choice of 5 different encoding options depending on image content and size and desired encoding time / data size ratio
- highly optimized data encoding for maximum save speed
- automatic data chunking in order to avoid Flash timeout warning with big images (except for turboscan mode)
- adjustable time slice for background saving in order to play nicely with the application and not to hog resources

BitmapExporter can theoretically save bitmaps up to Flash's maximum allowed size of 2880x2880 though it will take quite some time to save huge bitmaps like this. If you are planning to work with these sizes I recommend you to go for an AS3 solution since Flash 9 has much easier and faster possibilities to save Bitmaps.

[Important Notice] due to a non-backward compatible change by Adobe in Flash Player 10 security model the default behavior of BitmapExporter - popping up a file browser after the saving has completed - is not possible anymore and will create a security error. I currently do not have time to change the class to accomodate for that problem, but fortunately it is not that difficult to work around it. Follow the instructions in this blogpost.

NON-COMMERCIAL/PRIVATE USE:
The use of the BitmapExporter package is free for all non-commercial work if PROPER ATTRIBUTION is given. "non-commercial" means that you do not get paid for this work or you do not intend to sell it. "proper attribution" is a credit line somewhere VISIBLE along your piece of work which reads like this:

really nice stuff. Awesome work on PHP for native generation of BMPs and PNGs. I'm impressed from the set of "Save modes" which is very interesting in each kind of processing.

For sure currently some people work hard on AS3 libs which generate PNGs and other formats "on-the-fly" with Flash but you're right that this is too early to call it common (also because these libraries are still Alpha releases).

Mario,
We are trying to open up the Flash source and it keeps telling us it can't open it up. We clicked on the source link above and saved the file down. The guy who is trying to open it is on a Mac using Flash 8. That is correct, right?

John: Strange - I just tried to open BitmapExporter.as from the archive and encountered no problems. But I'm on Windows. This might be a mac issue. The demo fla had been saved from Flash CS3, but as a Flash 8 file.

Francis: that looks like a good solution you've built with the Unicode packing. I'll have a closer look at it. In the previous version I had tried to max out the available character to send data with but which made it necessary to keep Flash from sending Unicode chars via setting System.useCodepage = true - but it turned out that on some Asian systems this created problems. To use Unicode rightaway sounds much safer.

Hi Mario I was wondering if you would be able to help me with a problem. I have been searching for a way to retrieve a 300 dpi image instead of the standard 72 from a swf. Any suggestions or direction would be greatly appreciated.
Thanks,
Adam

Adam: From reading through the PNG format specifications I think that there is an option to add the resolution information to the file. For the moment I can only add that feature to the wishlist. I recommend you to run the created images through a batch script or a Photoshop action to change that info. I guess you are aware of the fact that the resolution info which comes with the image does not change the absolute number of pixels.

Adam, have a look athttp://www.duguid.co.uk/mike/businesscard/
I've mentioned in the notes there how to change the dpi of images saved. This is accomplished by serverside manipulation of the header data of the jpg.

I might add, this will probably only work on jpgs saved out by imagejpeg in php, jpgs sourced from e.g photoshop etc may have additional metadata in the header that might make the location of the dpi data different.

When i was looking for a way to save JPEG images in AS3 it took a long time to find out that adobe had AS3 classes for saving JPEGs and PNGs. I just wanted to mention that if you are using AS3 you don't need to go to any trouble to save JPEG images.

Here is a link to get you started with Adobe's utility classes.

P.S. Why not just convert the AS3 classes to AS 2 and use this clean approach to doing the conversion in the flash player?

Andrew: I'm well aware (and even mention it in the post above) that with AS3 there is a whole bunch of faster and better solutions available to save bitmaps.

There are at least two reasons why these solutions will not work in AS2:

- performance: AS3 is up to ten times faster when it comes to operations like looping through an array or converting strings.

- handling of binary data: Flash 8 cannot work with binary strings, or rather it cannot handle the chr(0) character because that is used as the marker for end-of-string. That is why in Flash 8 all these workarounds are necessary to work around this. Flash 9 has got the new ByteArray which even comes with a native compress() method.

Hi: This is great stuff. One issue I am getting, It is working great on my local machine, but I install it on the website, it is not displaying anything. I mean saving the output. I checked all the stuff requires are available on the server. Please help me.

Mike Duguld, your bussiness card demo uses AS2 or AS3? I saw it saves the JPG incredibly fast... what class are you using? I use this class and it's terribly slow for a jpg 500x375 (almost an entire minute to save it). I hope I can approach that speed someway
Thanks

Savador: the business card demo is so fast because it doesn't send the image as a bitmap at all but it just sends the infos like texts, template type, alignment etc to the server where the actual bitmap gets constructed from prepared elements.

Hi. Thanks for this great class. I just have one problem: when I click "save", he creates the new image on the folder "BitmapExporter_Tempfiles", and opens the window to browse. Then and choose the destination folder and click "save", but no image is saved in my computer.
Then I removed the code
+ ( deleteAfterDownload ? "&delete=1" : "" )
from BitmapExporter.as and this way it works fine, I can save the picture in my computer, but obviously, the image created on "BitmapExporter_Tempfiles" is not deleted after download.
Can you please tell me what I did wrong in the first case?
Thanks

António: I'm not sure what the exact issue is, but it looks like on some servers the file gets deleted before it actually has been completely sent - which is strange since in the php sourcecode the two commands come after each other. But you don't have to change the BitmapExporter sourcecode in order switch off the autodelete feature - just use the expression BitmapExporter.deleteAfterDownload = false;

BitmapExporter will automatically delete all images and temp files from the temp folder that are older than one day.

I am hearing such good things about this class, and I am excited to begin work on the proj that calls for it. My problem is that I need to do it on a .NET platform. Does anyone out there happen to have source for doing this on .NET?

hi there i can't make it work, i want to use it for education, can you help me, in the drawing demo looks amazing and thats exactly i want to kids can do, and they can sign their drawings, thanks and best regards

Hi Mario,
This is great for those of us still needing to do this in AS2.

One thing though - it seems I am able to download the image via the dialog box just fine - however when I follow your instructions to have it save to a file without downloading I get a File IO error. The temp file saves just fine, but I need to save an actual non-randomly-generated filename in a specific directory (and different directories for subsequent images, which means the paths will need to be runtime-generated) so that I can retrieve it and use later. Any Advice?

I don't know right now what causes the IO error, but if you want to create the images in a specific directory I would run a php script after the temporary file has been created which takes care of renaming it and moving it into the correct place in your folder structure.

now I can define where I want it to go from Flash. Seems to be working nicely. Also - It doesn't seem that I need to use getimage.php if I do it this way, as I just want to save the image and don't need to prompt a download.

Kevin: I do not allow to set the savepath / filename from Flash on purpose since that opens the possibility to anyone with malicious intent to overwrite files anywhere on you server. If you use this feature I recommend you to add some strong checks that the path/filename combination you receive is not doing any harm. Under no circumstances execute this command: $fp = fopen( $filepath.$tempFileName, "wb" ); without prior checks.

I've got the same prob as june 4th. Everything works smooth and fast, the image is created on the server, the save dialog box comes up, I click ok, but the image is not saved. I've set BitmapExporter.deleteAfterDownload = false;
in the fla and the .as. Any ideas?

Mario : those lines are uncommented already. I tried comenting them out, didn't seem to make any diference. I've just noticed, when I run it locally, the image is created on the server perfectly, but I get:

If I would like to store additional data, like a name or comments, where in the BitmapExporter.as file should I put this to be sent to the php file? The handling in PHP to a MySql server is no problem.

You can either try to add that code dircetly to BitmapExporter.php - in that case I'd probably put it into the "save" section. But I'd say it's probably easier to have a second php script to which you pass the imageID or the unique filename and which stores the extra info in a database. I would call that script upon the "saved" event of BitmapExporter.

It looks like you have uploaded the wrong swf to your server, since the one that is up there contains the line
BitmapExporter.gatewayURL = "http://localhost/BitmapExporter.php";
which of course cannot work.

I'm also having the same issue implementing this script - and I want to get it working because it looks like the best one out there. :-)

When I click "Save" the timer just keeps ticking indefinitely and no images are saved to the BitmapExporter_Tempfiles directory.

I tried the deleteAfterDownload:Boolean = false; change, as well as manually setting the $DOWNLOADURL to the server name. I'm not a full on coder but I know a good deal of PHP and Flash and have no idea what's happening.

I'm having the same problem. When I click "Save" the timer just keeps ticking indefinitely and no images are saved to the BitmapExporter_Tempfiles directory. I've tried it on two different php servers and the same thing occurs.

I have also set deleteAfterDownload:Boolean = false;, as well as manually setting the $DOWNLOADURL to the server name.

Do you know what is causing this problem and how to get around it?

I might also be interested in a commercial lisence but I would like to try the script out first.

I'm starting to worry that I am missing something crusual in the setup.

Normally setting the BitmapExporter.gatewayURL in the FLA and then create a folder on the server corresponding to $RELATIVE_SAVEPATH in php script should be enough or am I missing something?

Switching on logging in the php script generates nothing.
the line BitmapExporter.addEventListener( "error", this); exists in the FLA and I guess this should generate an error trace? This is what happens:http://www.sic3d.com/be3.html

Posted by: on July 26, 2007 11:14 AM

Okay, it looks like I have to add some safeguard for php running in safe mode and check if there is a problem with error handling in the initialization phase.

When I open your BitmapExporter3.php directly (which is BTW a good first test to see if there are any basic problems) it returns the following php warning: "Cannot set time limit in safe mode" - so for a quick fix you could comment out the line in the php script that sets the time limit.

Looking at your demo it seems to me that you are using an outdated version of the emo file - the textfield that shows the error messages is entirely missing from it and the timer doesn't stop upon errors.

I have updated the php file and added tests for php_safe_mode now before changing restricted values. The latest package can be downloaded here:

The new version works perfectly without commenting out anything. Great work!

Posted by: tod on July 26, 2007 03:53 PM

In order to use the "saved" event. What do I have to do apart from adding "BitmapExporter.addEventListener("saved", this);" in the FLA? Where do I write the code that I want to execute at the "saved" event?

Posted by: on July 27, 2007 10:14 AM

You will have to pass true for the dontRetrieve argument. Then in your FLA you have to add

So if you wanted to load the saved image back to the swf you'd use e.url. If you want to do further processing on the server side you could e.g. send e.fileName to another script on the server. For security reasons I would not use e.url here since a malicious person could alter that url and make it point to some other folder on your server. By just sending the filename your script will take care that only files in the temporary folder are processed.

I want to save with a form the name of author, the date. his e-mail,any one can say how to add this vars to the p h p or how to do something like that to save in a db?

Posted by: on July 31, 2007 06:08 PM

To save additional info together with the image just use the technique I described two comments earlier. Save the image first, then send the additional info together with the image location or its uniqueID to another script that you've written yourself and which stores everything in a database.

If you insist on sending it at the same time as the image you could change the code of the BitmapExporter and its php part, but I don't think that is neccessary.

Mario, great piece of Action script code. After building a graffiti application using your image exporter, I've noticed that some times once you press save, it begins its reinitialization process, but then stops with no error output or anything. It never begins to scan the canvas. Now, this is sporadic. What i do though, is continue to press save and maybe after the third try, it begins to scan and complete the process. Any ideas on what could be causing it?

Jorge: there is no error output? That is strange since in that case you shouldn't be able to save any bitmap afterwards. As long as the class is processing a picture it will not accept any other saving requests and that process can only be stopped by one of three events:
A - the image gets saved successfully
B - the process gets canceled by the cancel() method
C - an error occurs.

And if an error occurs there has to be an error message which you can listen to. Sometimes the error message is just "[undefined]" - that means that the php script has been interrupted by the server either due to an out-of-memory error or a timeout error (on systems that run in safe mode) and thus it couldn't send back a verbose message.

Is there a way to document errors once its uploaded to a web server and not via the output dialog box in flash? Maybe through some kind of text file on the server. Or output the error in the status dynamic text field? Since it doesn't happen all the time, and I've havent been able to duplicate the error when testing it in flash cs3.

It must have been an error, but since I was using it once uploaded to my server, I wasn't able to see what error it actually was.

You can activate logging on the server side, though that will only log those errors that happen in the php code. That would not catch any communication or timeout errors on the flash side. In your case you could send the output of the error event to a logging script on the server side of your own. But I will see if I can add some additional logging functionalities in the next update.

The image is generated by user, comes from Flash in ByteArray and is saved on PHP-side with file_put_contents, after downloading or showing in browser it is deleted. This works.
The problem is that I dont have write access on the server, so I can't create a temp-folder to put the file there and then delete it. I like to show the image in browser directly or download it but without saving it on the server.

Okay I understand. If you cannot store anything permanently on the server I guess you could at least store some data in a session variable. This might enable you to access the image data over multiple requests. Of course this will still limit the access to the one user who created the image.

1. When theres a camera connected to a computer, theres a flash security alert being displayed asking to allow flash to access your camera. There might be no way around this security warning if you wish to capture an actual webcam screen shot, but how do others who just wish to convert an image or other swf content get around from displaying this warning?

2. Once the image is saved on the server (in my case, a png image using the pallet method) I try to save a thumbnail of it using php's imagecreatefrompng then resizing it. But the smaller thumbnail image is almost always double the size of the original, non scaled version. Is there a way to save multiple width and height images at capture from your php script? Or, do you know of how to handle resizing of png images created with your script?

1. There is simply no way to get around that security warning and this is a very good thing. Nobody would ever trust Flash anymore if you couldn't be sure that your webcam is not secretly spying on them. As you know once the warning has appeared users can then decide to trust the site so the warning will not show up again.

But maybe I've misunderstood your question - if you just don't want that warning to appear because you don't use the webcam anyway just remove the Camera.get() part from the code.

2. Did you try to create a JPEG thumbnail instead of a PNG? Of course you could also try to scale down the bitmap on the flash side and just send it again with BitmapExporter, but I don't think that that's a really good idea. If I would have to do the resizing with my script on the server side I'd probably use GD or ImageMagick. Doing it manually just with PHP code will be pretty slow.

For some reason i thought the Camera.get() was essential for grabbing anything off the swf. Removed it and worked fine. Thanks for the tip :D

I wanted to stick with the PNG format for the resized images since the original was a png. imagecreatefrompng is a GD function and works really fast but for some reason the file sizes are huge compaired to the original one. I'll probably have to switch to jpeg for the thumbnails.

I read in your doc's: accepts transparent and non-transparent BitmapData objects, but currenty the transparency information is ignored and a opaque white background is applied to transparent images. This might change in a later version.
=> is there a 'easy way' to keep the transparancy?

in my application i 'cut out' the head of a person from a picture. Then i save it with your bitmapexporter. Later on, when i load the image into a movieclip. there is a (annoying) white background around my 'cut out head', i place off a transparent background :-(

Oh, well, the transparency issue... The reason I haven't done it yet is because I'd have to change quite a lot of code to do that. So the way to do it with the current version would probably be to first save a non-transparent version, then create a second b/w bitmap from the alpha channel (with the ColorMatrix filter), send that to the server and then have a script there that recombines the two with GD. But I admit that this doesn't sound too good either.

I need to know if it saves the image to the server temporarily and then removes it, or if it stays on the server after being saved. I want use this but having the images remain on the server is not an option for me...

You can save anything that you can draw() into a BitmapData object. So yes, it will be no problem to save an mc with multiple dynamic mcs inside. The only issue is when you load images or swfs from another domain than the one your swf is hosted on - due to the Flash Security Sandbox restrictions you cannot draw() those into a BitmapData. In that case you will have to use a server-side proxy script to download those images.

That's strange, you shouldn't get that warning, since I check in the code if safe mode is enabled. Have you installed the latest version?

Please check in line 215 of BitmapExporter.php if there are these lines:

if( ini_get('safe_mode') ){
if ($LOGGING) error_log( "WARNING: php safe mode is activated on this server, thus the script time limit can not be overridden. This might cause the script to quit prematurely on big images\n",3,$RELATIVE_SAVEPATH."be_log");
}else{
set_time_limit ( $MAX_CALCULATION_TIME );
}

if not, please download the latest version. If yes, it means that this method doesn't work all the time. In that case just delete this block. But it can happen that the saving will time out with very big bitmaps.

Awesome work, you are a god. However, I am about to use this class for a commercial project, I have tested locally all is fine. Then I uploaded to my server and I have had problems, the downloaded file is under 1k and will not open. I swtiched on Logging and looked at the tmp files, these seem however seem to be of the right file size but are still corrupt and will not open. I have been using jpg and then tested with png and still got the same result. This must be some sort of stupid server issue, any thoughts?

Sooty: I'm not sure the reason might be that the dropImageHandle call comes too early, and thus the temporary image is deleted while it is still downloading. You could test this by setting
$KEEP_TEMP_FILES = true; in line 202 of BitmapExporter.php

Dan: I don't know of any .NET ports yet, but I'm always happy about volunteers ;-)

Isn't that rather "[onImageHandle] undefined"? That is the error that appears when the PHP script gets interrupted before it can send back a proper error message. Which is usually either caused by an timeout or an out of memory error. You should check the php error.log on your server to get some detailed information. The BitmapExporter.php also contains some comments what to do in that case.

I was trying to get output from a movie clip instead of a Camera. So i implemented this coding.
var snapshot:BitmapData=new BitmapData(800,600,false);
snapshot.draw(output_mc);
// Where output_mc is a movie clip on stage.

it gives me Error as
"A script in this movie causing flash player to run slowly. If it continues to run it may be unresponsive. Do You want to abort the script? "
When i click on yes button it gives me nothing.

I guess that you have used the "turboscan" mode. If you read the documentation you will see that it says that "turboscan" mode should not be used for images bigger that webcam shots. Please use "fastscan" or any other mode instead.

No, there is no vector format possible since the vector information gets lost as soon as you draw() into a bitmap. Also Flash has no native Actionscript method yet that allows to read the vector data of embedded symbols. The common workaround to export vector data from flash is to use the print command and print to a PDF. This method only works locally though.

As I mentioned above - if you get this error, please try first to set $KEEP_TEMP_FILES = true; in BitmapExporter.php - search for "$KEEP_TEMP_FILES" to find the right line. This seems to be an issue with certain servers or OS, but I still haven't found out what causes it.

Thanks Flasher_007! Oh yes of course - I didn't think of that - you have to make sure that the $DOWNLOADURL variable points to the location of the BitmapExporter.php file. In the default configuration it assumes that BitmapExporter.php is in the top level of your domain. I think I could make that easier by just using $PHP_SELF in that location. Gotta try.

The BitmapExporter is great, and it works fine on both a xampp server on my pc and another php 5 server. But sadly it wont work on another server using php 4. Can this be a problem. Al servers have GD installed.

I get this error:

[onAddPixelBlock] HTTP error 200

When I google, 200 seems to mean "The request has succeeded", so I have no idea what's wrong. Maybe you have help me.

Anyway... I've tried this on 4 different servers so far with different setups. I haven't gotten any PHP errors, but the image always ends up white.

I tried someone else's method before yours, and for some reason, all my pixel color values were changed to a '1' when they hit PHP through POST... any ideas? I'm going out of my mind here, and I'd owe you big time if you can think of anything...

Riddle me this.... it runs fine when I test it in the authoring environment...all paths in the FLA, AS, and PHP are absolute paths.... it runs fine. As soon as it's in a browser, it generates the file, gives no error, but the file is blank white.

Traced it as far as I could.... when running in the flash authoring environment, variables come through POST fine, but on a live server, (i've tried 4 different servers w/ diff configurations) the values come in as comma-delimited single slashes ( / )

My application includes more than one movieclips. I have taken all clips into one clips and some of them are masked. The application runs perfect in point of saving. But I am facing a peculiar problem. At the time of saving it clears the mask and show the entire rectrangular clip that was masked. Needless to say that the image saved in database is perfect and without any distoration.

Hi, I am working for my MA project and trying to create an online drawing board.

I have applied the BitmapExporter to my app, and successfully called the snapshot and export to the subfolder where the temp files are store in my local host. But when I press the "save" from the pop up location select window, an error message appeared in the errormsg text box:

ERROR: IO error with file MyDrawing.jpg

Also, I try to uploaded to my server, and when I export the jpg, an error message appear as:

Thanks. You were right. There was something wrong about the path where the images go. I put it outside the php folder (instead of same directory) and therefore AS got lose and cannot retrieve that piece of information.

Sorry, I need to ask another question. It is about this:

Is that anyway I can modify the name of the temp file which you export to the temp folder? Let say same as the one I can save onto my desktop.

I have created a text filed on stage. So, I can trace a variable after the user input the name - otherwise, defaulted as "MyDrawing".

I have done that for the one save locally, but don't know how to change the temp one.

Do you have any suggestion?

Also, as to consider I am using the BitmapExporter, I would like to put a "credt" line of you and your web site on my degree show which is in 5 weeks time. Please contact me personally for more details.

For security reasons I decided that it should not possible to set the name of the temporary filename via actionscript. Also it is important that the temporary filename is unique in order to prevent name collisions in the temporary folder when there are two files named "MyDrawing". What you can do is to create a second php script which will rename or copy the temporary file after it has been saved. In that case you can create your own security measures and deal with duplicate filenames and such.

A copy of temporary file, a good idea. Thanks again Mario. Will update a link to you when the whole project finish.

The project is much like million master piece web site. But the different is that once the user save their image on server, it also tells where and when they create the image. Like google map, instead, the map I make will be fill with images.

hey mario, matt again,
its posting the files to my server, but there's no picture, and the file size is 0kb, again, i'm getting the error "ERROR: [onSave] undefined idle" i've tried using png's and jpg compression methods, i'm not using a web_cam, but instead trying to draw the content of just the mc

Keni - if you get an error like this, just enter it in google and you will find an answer in 95% of all cases.

You are not supposed to enter the full url as relative savepath. That is why it is called RELATIVE savepath. This is a local path on your server's filesystem. It cannot be accessed via http:// - a relative path is the path from the BitmapExporter.php script to the temporary image folder. If you just renamed the temporary image folder to "images" and it is on the same level as the script the path will simply be "images/"

Matt - you should check your PHP error log. As I have written several times in the comments above [onSave] udefined is usually cause by an out-of-memory error or a timeout. It is not possible to give a proper error message back to flash in this case, since the script gets interrupted by the server. You might have to check your php.ini file and give PHP more memory.

Thank you for the advise. The app works now. There is only on the last (I believe). It is still now saving onto my desktop. I find that when I press save from the pop up window, there was an 404 error on:

Sorry I don't understand what you are trying to do. Do you want to download the images or not? If you don't want to download the image automatically use the "dontRetrieve" argument as it is written in the docs and I have repeatedly mentioned in the comments on this page.

i am exporting as png, and have increased the amount of memory allocated to php, however I am still recieving the "ERROR: [onSave] undefined idle" statement, are there any other reasons that would cause this besides the memory issue?

I have it set up so that there is some dynamic text in the area that gets exported as an image... my problem, however, is that even though the text looks clear on screen in the movie, in the saved image it shows up really blurry/pixelated.

I tried converting the text to bitmapData to see if that would help, but it didn't...

Any ideas?

Thanks,
-john

Posted by: john on October 21, 2007 01:42 AM

John: it might be caused by the JPEG compression. Did you try to save it as a PNG instead of a JPEG? Or setting the JPEG quality higher? Or are you scaling the type in Flash in some way and the actual resolution of the bitmap is lower? Did you try to display the actual bitmap that you save inside Flash to see if the problem is already caused when you do the draw()?

Oh well - I really should take the time to write an FAQ or a better documentation...

If you don't want to download the saved image automatically you have to set the dontRetrieve argument to true. Please check within the comments above for further details - I've answered that question several times already.

Thanks for your response. I had actually just figured out the day before you responded, that if I used PNG it solved the problem. I guess just since the spacing between and around was being seen almost as transparent maybe..? and the jpg couldn't render it as well as png.. (the text itself looked good, but the areas around and between the letters was pixelated with jpg)

Thx for your response, as if I hadn't figured it out just hours before your response I would have been fortunate enough to see you provide me with the correct solution!

-john

Posted by: john on October 25, 2007 10:06 PM

Hi Mario!

I love your program, but recently I have been experiencing a problem on some PHP installations and not others. It occurs during the image creation routine. The error that gets output to flash is:

"ERROR: [onAddPixelBlock] NOTICE [8] Undefined idex: bitmapString"

(It's not actually "idex" but your spam filter flags the real word)

To me this means it is having a problem with the bitmap data php is receiving from Flash... however I can't figure out why it works fine on some PHP installations and not on others.

I have previously had BitmapExporter working on the same installation that is now giving me problems! I have tried increasing the timeslice and timeout values.

This is not an error but a notice message from PHP which means that the warning level on your server is set to very very low. You should change the php.ini settings on your server to only show real errors if you can.

This problem might also be fixable by defining that index somewhere in BitmapExporter.php, but unfortunately you have to try that yourself right now since I'm on the way Flash on the Beach.

I got around the error/warning/notice message and the problem is actually on line 251 of the BitmapExporter.php file, specifically the setting the $bitmapString variable to $_POST["bitmapString"]. It appears flash is not able to send any data to PHP (or that PHP is not receiving any data from flash) because it won't even create a .tmp file. If I'm not mistaken, bitmapString (from the .as file) is a string created out of the pixel[] array containing pixel data for most of the scan methods.

I can't figure out what setting would restrict this passage of variables between layers (Flash and PHP)... I can send dynamically created emails from flash (which also uses $_POST[""]) just fine.

That leads me to think that bitmapString (or perhaps the pixel[] array) is infact empty and that why it is undefined when it hits PHP.

Again, any insight or help you could provide would be greatly appreciated!

Internet providers release information about their users at the first official request. Your ISP, your boss, or someone can be monitoring all your internet activities at this very moment.
Some users might want to enjoy more privacy than that.
That is why you should use the internet-anonymity service.

Hey Mario - First off, amazing work here. I'm blown away when I see my 300x300px vector image save in less than 5 seconds. (using palette mode) You've made this extremely easy to use man. Anyone who has ANY problems whatsoever, does not know much. hehe.
So thanks a lot and you will hear from me soon about compensation for a commercial project. :)

Posted by: Nick R. on November 9, 2007 05:10 AM

hi all, i have tried this application locally and it works fine. However, when i tried upload my school's server the image does not save correctly.. the jpg image is always 0 kb although the TMP file created is around 20+ kb. (i have already set dontRetrieve to true)

- incorrect pathes in BitmapExporter.php
- no write permission in temporary folder
- no GD on the server
- not enough memory for php
- php warning level is very low (notices are on which breaks communication with the swf)

Did you make sure that all the pathes are set correctly on the server? Did you already switch on the logging option in the php file and checked the log file afterwards?

thanks for the prompt reply mate, much appreciated.
yes I've set dontRetrieve to true, and that's all working fine, and am now using 'onSaved' and I'm showing my 'finish' message, so thanks again. Job done there.

One last thing if you don't mind: I now need to get the path for the new image and Post it to my email form. How would I retrieve the random image name?

Everything works fine until i finish the Save file as dialogue. The swf gets stuck while showing "downloading". No file is written on my hd or in the temporary dir on the server (I disabled deleting it in the php and the as). The browser is transfering data but nothing happens. When I hit cancel the downloading sign still is shown although the browser stops.

When accessing the php-script on the server directly i get "success=1".

I have the TamperData Add-On installed but have no idea what it should say or what kind of hints it can give me. The last entry is a crossdomain.xml entry with "not found" status.

Hey im having a little problem here. When I run the script locally, works great, and I went through the php file to ensure there were no incorrect paths. When I upload to my server and use it there, I get the following error:

ERROR: [onImageHandle] HTTP Error null

Any known cause for this? I looked through everything :\

Posted by: Chris on November 25, 2007 10:08 PM

ok now it works past the capture portion, but after I specify a location to save the file, it freezes at "downloading" and I don't see it on my computer. I do however, see it on the tempfiles.

eh?

Posted by: Chris on November 25, 2007 10:54 PM

Hi Mario,
I have come across you Flash code/tool which seems very impressive. I've taken a look at the code (a bit beyond my skills to be honest!) as I'm trying to do something very specific with Flash and so far, your solution seems to be the closest.

I was hoping that you could advise me if you think your solution could achieve what I'm after, without me spending hours going through your code and realising it doesn't do what I'm after. Not being lazy, just a bit busy!

I have a Flash movie where a user can upload a photo, then modify the scale and position within a movie clip. There are also other layers which they can change; border colour, enter their name and few other items. They can then save this movie clip, which is currently done by saving the image and various parameter via XML to a database. What I need to do is actually save the users uploaded image with the various updated movie clip elements, as an image to the server (doesn't need to be sent back to the user). My worry is that your method appears to be taking a screengrab (am I correct there?) and the saved images on the server will actually need to be printed as best quality as possible. Just not sure if a screengrab would be good enough for this.

I was trying to find a way to just save the users finished movie clip as an image, which doesn't seem to be possible.

Can you help?

Btw, If this or another solution does work then I would be willing to pay the commercial license fee.

BitmapExporter allows you to saveanything that you can see on your Flash stage as a Bitmap. The maximum size for a single Bitmap is limited by Flash to 2880x2880 pixels which, printed at 300 dpi, will give you an image of 9.6 x 9.6 inches or 24.3 x 24.3 cm. If you need higher resoultions you would have to build a soultion that tiles your canvas into multiple pieces, each using the maximum allowed dimensions. Though I must say that I wouldn't use BitmapExporter for that since even one 2880x2880 picuture will take a considerable time to export.

BitmapExporter does not take a "screengrab" but sends a BitmapData object that you provide to the server. So it is entirely up to you how you create that BitmapData object. So for example if you display a scaled down photo on screen with some vector graphics on top and you want to export that in the optimum resoultion, you should create a BitmapData that has the original dimensions of the photo and then use the draw() command together with an appropriate scaling matrix to copy your composition to that bitmap.

Hi,
great tool, however I am having two issues that someone maybe able to help me with. One that when it retrieves the image and pops up the dialogue box it doesnt have an extension... Also when you add the .jpg extension and save it to the desktop, it only shows half the image. Can you/anyone help??

What you created is amazing!!!! I read all of the questions people have posted and none suit mine. Everything is working I got it to save from my websever but it save a small piece i would like to make the image bigger.

I changed var snapshot:BitmapData = new BitmapData(500,300,false) to different setting i see but my image is the same. Sorry to bother you with this

This is a very cool little class. I'm having fun playing with it! I am trying to figure out where to offset the image that is being generated.

My MovieClip is centered, and not anchored to the top left. I've tried adjusting the matrix, but that doesn't seem to do anything. Rebuilding "turboscan" just seems to reflect my ignorance, as it kills the whole thing.

When you draw() a clip into a bitmap the transformation matrix or its position, scaling or rotation on the stage will be ignored by Flash. If you have scaled, rotated or repositioned a clip and want to use draw() you will either have to supply a matrix yourself or you nest it inside another clip which you do not scale or reposition and then draw() that clip into the bitmap.

What you can also try is to either use this:
yourBitmap.draw( your_clip, your_clip.transform.matrix );
or this:
yourBitmap.draw( your_clip, your_clip.transform.concatenatedMatrix );
but no guarantee that it will work with your individual setup.

It looks like the script does not have write permission to your "BitmapExporter_Tempfiles" folder. Or you've set the path to it incorrectly - remember that it has to be a relative path from the folder where you've stored the BitmapExporter.php file.

mario
in addition to my previous post - when i copy the script to my application i get
"error"...line 177 classes may only be defined in external actionscript 2/0 class scripts"
what does it mean?
ehud

Sorry but I cannot give you an introduction to Actionscript 2.0 here - please press the F1 key inside your Flash Application and read the really good tutorials there. There is even a search option so if you search for "classes" you should find plenty of starting points.

Only so much: you do not paste the code which is contained in BitmapExporter.as into your fla, but you have to copy the folder structure and the as into the same folder in which your fla resides. You can also manually create those folders:

- Go into the folder in which your FLA sits
- create a folder called "com" if it does not exist yet
- go into the "com" folder
- create a folder called "quasimondo"
- go into the "quasimondo" folder
- create a folder called "display"
- go into the "display" folder
- copy the file "BitmapDataExporter.as" into that folder.

mario.
i succeed to upload image on server however instead of name it is filed by long row of numbers. this of course prevent from dpwnload the file again. i assume i did not configure th "name" correctly.
please help
udi

Posted by: udi on December 28, 2007 03:53 PM

The file name with the seemingly random numbers is the unique file that gets created for each upload. That is entirely correct and made like this for security reasons and in order to prevent that files with the same name get overwritten. Please read my answers to several comments above how to deal with this unique file afterwards.

To debug your browser->server communication I recommend you to use Firefox and the "Tamper Data" extension. This will swhow you pretty quickly if you've got your path wrong or if there are any other communication problems.

Since you want me to help you with your page you should at least conform to the license conditions of BitmapExporter - I do not see any backlink to my site on your page.

But to me it looks like this already works now at least I could save a bitmap without problems. Though you probably should change the chunk-size and/or the timeslice variables so the saving process becomes more responsive.

That error means that something's fundamentally wrong with your php script since it doesn't even return a proper error message. The first thing you should try is to open the BitmapExporter.php file on your server in the browser. Like this you will see if you maybe introduced a syntax error whilst editing the path data.

Hi again Mario
I am just using the temp file so store the image, I dont need to save it to a local computer, I read the comments above on what I should do for that.

My fla is outputing another file that is saved and I would like to use the same variablename for the image too. Since that name has a unique name how can I make the tmp files save with that unique name?

Hey im trying to get this to save the file locally. I.E. On the server. And not send it to the user. SO far i see that its saving to a temp folder. Is there any way i can pass a name to the file through flash?

Thanks so much for this piece of code, it has made my last project MUCH, much easier. I integrated the AS and XML into a modified interface and I'm very pleased with how it is performing...well, mostly.

I'm not sure if you can help me, and I know you get inundated with questions here, but here goes.

I have an interactive coloring book at one of my sites. Illustrated as Flash layers it works like this:

If I set "snapshot.draw(coloring_page);" then BitmapExporter pulls the PNG but none of the color information underneath it (which is, I think, to be expected according to the code comments? This is due to not handling transparency, right?). This happens in palette, default, and rgb_rle. But I'm pretty sure that's what should happen when trying to grab a transparent PNG.

If I set "snapshot.draw(canvas);" (which is where the actual colored lines are being laid down) then in palette I get a colored rectangle (whatever color I set the "canvas" rectangle to be will be saved to the server and returned). If I try it in rgb_rle I get an "undefined offset" error. In "default" it will time out (return HTTP null).

The camera is set to grab 500X500 pixels, the XML file is set up to give PHP 32 megs, the images are being saved on the server and back down to the desktop just fine.

So do I understand it correctly that in your setupo you have a canvas clip and on top of that is a color clip and you would like to save both of them merged as a bitmap? In that case there are two ways to do it:

A- put both of them into a holder clip and then draw() the holder clip onto the bitmapdata that you want to export. This is usually the easiest way since it will also make it unnecessary to use a special matrix in order to adjust the scaling.

B- first draw() your canvas onto the bitmapdata, then draw() your color layer on top of that same bitmapdata. Note that in case you have scaled or repositioned one of those layers on the stage you will have to use a matrix in order to reproduce the same transformations on the bitmapdata.

If you feel confident enough to alter the BitmapExporter.PHP code and the AS code feel free to add another command there. I probably would rather create a separate php file which handles the mailing and to which you pass the uniqueID of the image on the server.

Caution: whenever you do a script which does automated mailing you should watch out that it cannot be abused by mail spammers as a relay station. So for example it is a very bad idea to have a script which receives the receipient, the sender, the subject and the message all in one GET request and then just uses the mail() statement to send the mail. Either encode your variables (which of course could also be reverse enginieered) or add some security checks to make sure it was really your flash file that started the request.

Hello Mario,
Thanks for the reply and the advice. Unfortunately i am looking for this and i am not a PHP coder, therefore do you know any link where i can get the same thing and merge it with your PHP?
OR
Can you add this little feature into your existing code or as an extension like that we call that file from your PHP when the JPG has been downloaded or exported?

i am using adobes com.adobe.images.JPGEncoder class for encoding images to jpg using action script 3.0 in Flex 3 . and then compressing the bitmap data using byetArray native compressing method into gzip format .Then exporting it to the .net server as post raw binary data stream.THen on the server side c# code retrieves bitmap data stream from post and writes it on the file system every thing works fine .But when Flex starts encoding bitmapData into jpg format flash player stucks for the time its encoding if the image is of 800X600 pixels and quality =50 % flash player remain stuck for about 30 seconds.SO is there any way in flash support of multithreading so that all heaving encoding to jpg format is done in another thread or any other alternatives to avoid this glitch

i was finding a solution for it over internet. THat localConnection can be a good solution.SO i tried to use that approach.THat i embeded helper Flash movie in browser along with main Flash movie.BUt the result is the same after sending all jpg binary data to the other helper movie over localConnection and when encoding starts over there it stucks the whole browser window.All in vain

any suggestions about it

regards Atif

Posted by: ATIF on March 15, 2008 02:55 PM

Hi Mario - still developing the app - not sure if the accounts have paid you.

However, i think i have found an odd bug - the "saved" event returns the same url everytime its called. It returns the link to the first image that is generated. The strange thing is that the onSaved function in BitmapExporter receives the correct URL. but for some reason the 'saved' event function receives the old image. I am publishing to FP8... any ideas?...

Hi mario , i am getting crazy .. i read all the posts looking for a solution , all works fine when authoring but i tried on 4 diff servers and i only get blank images , i enabled php log and all seems ok , i am not getting no errors , i guess i am posting blank variables from flash but i dont know where to start looking for. any ideas?

Hi mario , i am getting crazy .. i read all the posts looking for a solution , all works fine when authoring but i tried on 4 diff servers and i only get blank images , i enabled php log and all seems ok , i am not getting no errors , i guess i am posting blank variables from flash but i dont know where to start looking for. any ideas?

If you are getting back black images then you are probably trying to draw() content that you loaded from a different domain to a bitmapData. Search google for something like "flash bitmapdata draw security" and you will see what I mean and also find some possible solutions.

i'm trying to create an offline drawing app that can save the drawings locally. second prize is that i go online to save their images. i've tried your code and its working if the swf and the php are on my server. can it work if the app is an exe? or at least in an html page on the local machine that connects to the php online?

@templar: there are two ways this can work with an exe - when you are sure that the user is online you could have the BitmapExporter.php script on some server and have the exe send and receive the data to and from that url. Alternatively you could use a local server like WAMPserver and run the script locally (in which case you would connect to http://localhost/BitmapExporter.php) - of course that solution is probably not feasible if you plan to distribute your app.

Honestly I think the best solution in your case is to write your application in AS3 and then just use Adobe AIR. Then you don't require any server but can generate and save JPEGs and PNGs directly.

I'm evaluating this for an upcoming project. I have it running locally and it works. But the speed is an issue. I have a thought that in my situation might speed it up. I am rendering letters (drawn by Flash) over a pre-defined bitmap. Both exist in the movieclip that I draw(). I am wondering if it would be possible to only send the Flash piece and have it merge with the bitmap data on the server-side. So I would just have my letters in the draw(), and overlay that bitmap data over the top of the bitmap image data, that is read in on the server-side. Would this be possible, or is merging of two bitmaps data not possible?

if you are able to run Image Magick on your server then blending several bitmaps together shouldn't be a problem. Of course you would have to write that code yourself, but I think this is something like 5 lines of code. Sending just the type is definitely faster since that kind of graphic content will also compress better than a photo.

If you don't do any scaling and rotating and the background map has the same dimensions as the type layer one could probably write some php code which blends both layers "manually", but that would run quite slower than the Image Magick version.

This error is caused by PHP which on your server is configured to be very talkative by probably having the error_reporting set to error_reporting = E_ALL. This means it not only reports errors but also "notices" (in this case an undefined array offset) and thus inserts junk text into the data that gets sent back to Flash. In your php.ini you should activate either this line
error_reporting = E_ALL & ~E_NOTICE
or this one
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT

Thanks Mario for a great piece of software. I've been evaluating this for a webcam application, as well as for generating jpegs of user generated avatars, and it works really well. I haven't found anything else to match it.

I hope you continue to support and develop it further, the comments on this page alone stand as testimony to how invaluable it has become for many developers!

This is excellent. I only have one question, you see, I have a movie clip in the stage that cointains a short story of 5 frames ( I also added buttons in the stage to move to 'scene1', 'scene2', and so on..), I want people to be able to save an image in jpg of the scene(frame) they choose instead of an image from a webcam... is this possible?

I just can't figure out how to .. I tried by giving the movie clip the same instance name of image_mc, but didn't work

sorry if this is kind of newbie, hope u can help me

Posted by: Sam Lee on June 18, 2008 03:55 AM

The easiest way to do this is to nest all the clips that you want to include in the final bitmap snapshot inside one movieclip and then draw() this movieclip into the bitmapdata. If you don't want to deal with transformation or drawing matrices you should place that parent movieclip so its upper left corner aligns with the upper left corner of your snapshot area.

ok..I see to have a fairly stable working version going now.. TurboScan and anything UNDER Palette just doesnt work for me on my host.. (not sure why) but using RBG or Palette seems to have been my missing piece finally

From the comments, Id like to get some feedback/confirmation on this comment:

"I'm not sure what the exact issue is, but it looks like on some servers the file gets deleted before it actually has been completely sent - which is strange since in the php sourcecode the two commands come after each other. But you don't have to change the BitmapExporter sourcecode in order switch off the autodelete feature - just use the expression BitmapExporter.deleteAfterDownload = false;

BitmapExporter will automatically delete all images and temp files from the temp folder that are older than one day."

I am in the same situation, if I have auto delete set..things wont work..

but everytime someone saves an image (with delete set to true) it will scrape the directory and delete any images older than 1 day?

good to hear that you have at least a half-functional version now. Maybe there is some problem in the compression/uncompression algorithm which only happens under certain circumstances - do you always test with the same content or do you use different images? What happens for example if you change the image width/height by a few pixels?

Yes the scraping of old files in the temp folder is done by the BitmapExporter.php file whenever the "download" method is accessed - it's internally called cleanUpTempFolder()

well I found that the image was WHITE because the objects on the stage were all over the stage area.. and it seems the parent clip all these other clips were nested in were NOT on the X:0 and Y:) values to be included in the snapshot?

I thought I read a comment on someone else running into this problem?

I have been moving he bitMap height/width properties up little by little to find a cap out..

it seems 300x 300 works.. however 400x400 throws an error.. I get aTON of different and random errors

After playing with the same image and like images (app is a simple drag/drop builder demo...all draggable clips are nested in a 1 parent clip 'containerClip' for arguments sake) ;) I have it hard coded to be roughly 850x500 set to Pallete param @ 50% compression. and it IS exporting.

the parent/containerClip all these draggable/builder clips are nested in, starts at empty @ X:0 & Y:0 positions.. until other clips are loaded into it, and then those nested clips are obvioulsy placed/moved around however.

when I print.. I have to get the whole 850x500 size because the parent is at X:0/Y:0 but the content of that parent are roughly in the middle of the stage.. or offset somewhat..but not near 0/0.

Is there a way to ONLY capture the DEFAULT (dynamic) size of the parents CONTENTS? so I only get the contents in the parent.. and not the 850x500 around it?

it DOES seem to be creating an image the CORRECT size that mimics the content on the stage.. however the images are still white..because the nested clips are NOT starting @ X:0/Y:0 placement values..

also the SIZE seems to be dynamic and correct now (no extra junk outside of the content (nested clip) size.. however I need a way to get a snap shot of ALL the nested clips inside the parent clip.. if if they are located centrally on the STAGE and not X:0 & Y:0 in relation to the parent clip.. (hope that made any sense)..LOL

things are working fine.. I do have a question(s) of a few loose ends though..

1.) sometimes.. I see this error log on my domain:
[04-Jul-2008 10:57:00] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/whispers/public_html/demos/saberBuilder/BitmapExporter.php:613) in /home/whispers/public_html/demos/saberBuilder/BitmapExporter.php on line 633

(even though I DO get image output still)

2.) I am still wondering about the 'clean-up'

I have to turn OFF the delete after creation because it doesnt load/display fast enough...

but I read that the PHP file shoudl auto clean the directory of all images older than 1 day (which is an awesome feature)..

but I cant that it is working for me.. does this need to be turned on? (un-commented) or something? somewhere?

I believe it is set by the snapShot() bitmap data and the size of the web cam holder/component

hope that helps.

if anyone has the auto image deletion after 1 day working, please chime in.. or any sort of AUTO clean-up working.. I have to turn it off by default as then the image wont be loaded fast enough before deletion, but I read the script is supposed to scrape the directory of images anyways, and delete any images older than 1 day? is tis NOT the case now?..and if so..how can I get it to work?

The reason is that since I use the topmost bit (0x80) as a marker for a run length encoded line the maximum allowed offset is 0x7fff. Which means that any longer run must be split up into multiple runs.

Superb class, and I've got it working pretty well, however I seem to have a few problems with the eventListeners. Basically whenever I try and add an eventListener Flash gets stuck in an endless loop, and looking at the code i can see why as calling addEventListener just calls itself. What's strange is that no one else seems to have mentioned this issue yet, and it seems to work in the IDE so maybe it's got something to do with the fact that I'm compiling my project in Eclipse using MTASC? I'm using FDT to code it too.

It's super easy to delete files older than a day, maybe 10 lines of php. I'd do it for you, but you know what *the world is not your slave*.

Suggest you look up php documentation on finding a files age, and looping through files in a directory. It's mega easy.

Posted by: php-is-so-easy on August 20, 2008 07:53 PM

Thanks.. (sorta)..

but isnt it ALREADY in the .php file were using here? I was in the understanding that it was. If it isnt, ten my mistake, but I was wondering on how to get it working in this file were already have presented to us in the bitMapExporter file...

php-is-so-easy.. but I know very little of it, ore of AS only..

and the world is not your slave comment is not needed. Simply, have you gotten it to work in the .php file that Mario supplies or not?

I have a problem with masks. When I try to export the mask isn't applied, but is drawn in the jpg. The mask is applied through actionscript. In the swf it looks right. I use snapshot.draw(_root); to export everything on the stage.

I’m building a drag & drop game, which is a Movie clip. What I’d like the user to able to do is save an image, in jpg from the drag & drop stage. Is this possible? If yes can you show me how to go about it. I’m running Flash 8.

That means that there is a problem and you should check the error log on your server as well as listen to and trace out the error event that the bitmapexporter fires. You can also watch the communication between flash and your server with the help of tools like "Tamper Data".

The first test you should always do is to try to open the url on which you reach bitmapexporter.php on your server in your browser and check if A) it is at that url and B) if it returns any php errors.

If you want to combine multiple clips in one bitmap you will have to use the draw() comand with a correct matrix and probably also provide a clipRect so you only draw into the areas quadrant that you intend to and not bleed into the previous ones.

Thanks for your help with the previous question, I was able to get it working.

Now my problem is this: the jpegs it's saving are coming out 0x0/no information (and I know the bitmapData i'm sending it is correct.) Is there a common reason for this problem? I feel like I must be missing something really obvious, but i've been staring at the code all morning.

I worked on an other, less highend jpg-exporter on AS 2 too, and now, in de field tests, we have a problem with several users: the image is cut. It looks like the pixel - string is cut.
We have this problem with diffrent users and don't know, if the problem lies at the browser conficuration or at an older version of flash-player.

Thank you very much for this little and yet very powerful tool you've provided! I haven't published this class anywhere in my sites but I'm about to.

I now ran into very weird problem. Now I get error message with onSave dialog every time no matter what the current setup is. I finally narrowed down the problem to the very newest Flash Player, version 10.

I'm not yet sure what is the feature in F10 that causes the dialog failing to open but I'm going to find out.

If you have got some ideas or maybe a direct "bug" fix for this issue, it would be greatly appreciated.

oh damn - you are correct. The latest changes in Flash Player 10's security model do not allow that a "save to disk" dialog box is opened without a mouse click. Since in BitmapExporter the box pops up automatically after the upload has finished there is no mouse click and thus flash Player 10 breaks it. Oh well, that means that for a temporary fix one has to keep the file on the server and then provide a link to the user for which he can download it with another click.

Hi, I downloaded the class and it's amazing. But I'm having some problems with it. I'd like to use it for a personal non-commercial project , and I saved the code on the server, I can see the stream of my webcam on the client, but can't save the .jpg snapshot of the webcam, because I get errors like permission denied on the folder I want to use to save the pictures, which is on the server as well, in the same folder as the swf and php files. I can't figure it out, what am I doing wrong?. If you could help me with this. Thanks a lot.

Sounds like php does not have the permission to write to the folder where you want to save the images. So you will have to change the folder permissions so it can be written into: http://en.wikipedia.org/wiki/Chmod

I have an issue though, similar to ones mentioned above, in which case the save dialogue box opens, but when I save the file it tells me an IO error has occurred. It doesn't seem to be generating anything in the temporary folder, but I believe I've updated the code with my server in all the right places. Could this be a problem with the server and PHP? Thanks.

I am having a strange result using this PHP script/class all of a sudden..

while it worked for a while.. I came back to the project..and tested it.. (from a known working version)..and now (while the image DOES saved on the server)... I am NOT receiving any SAVE AS dialouge box anymore? any ideas on what could be causing this? and how to trouble shoot it?

Again.. it works only sometimes.. (usually ony in Internet Explorer) and never in FireFox anymore? I would say 90% of the time (any browser) it does NOT prompt for a SAVE AS box anymore?

any ideas?

Posted by: xl97 on November 7, 2008 07:28 PM

Due to the comment spam that some moron keeps adding on a daily base you might have missed one of the comments further above: yes that problem is know and is caused by the new security model of flash player 10 which is not backward compatible - unfortunatley a really unfriendly move of adobe.

ahh,... yes I see it now.. (and yes it was because of the spam..sorry to see that junk going on)..

is there any fix to be had? Im not so good with PHP..is there a function or event that can be called to initiate the save as box after you get a return of the save being completed perhaps?

maybe something that returns the $uniqueID of the image crearted, so another button event can prompt the SAVE AS box?
Just talking out loud I suppose..

Posted by: xl97 on November 10, 2008 04:33 PM

sorry to post again... maybe breaking up the script into two parts? Or helping us do it ourselves? one to save & create the image on the server.. where it passes in the $uniqueID name of the image it created on the server..back to the onComplete listener? and then another part where we pass in that var into the second php script to envoke the SAVE AS box..and actually save it to the local machine?

thanks

Posted by: xl97 on November 10, 2008 04:58 PM

That's the solution I proposed further above and you don't have to change the class at all - you simply set the dontRetrieve argument to true and listen for the "saved" event which will provide you with the url to the saved file on your server. All you have to do is then to create a link that people can click on and trigger a save box.

How would you adapt this to take a screen shot of the stage? This is a bit over my head but I just need the save button to grab a shot of the screen or a certain pixel area. Right now you get it from the cam.

i have notice that the coding probably PHP is a little corruptep when i hit save images the image is in the BitmapExporter_Tempfiles but it show and msg "ERROR: [onSave] Dialog box failed to open" show up.. how do i fix this problem.

Please guys - if you encounter a problem with BitmapExporter take a few minutes and look through the comments on this page first to see if your question has been answered already - CTRL-F on Firefox might be useful, too. I'm currently a bit tired of having to answer the same 3 kinds of questions again and again.

BitmapExporter.php should be in the same domain where the flash is calling it ... (possibly sandbox issue - although i have domain.xml in other site but i still getting this error .. so i transferred BitmapExporter.php in the same domain where i play the SWF and wallah! no more error ....

hi i tried this sample you given.. i worked out with my php colleague too. my project is based on a floor tiles porject. so each time the image tat is the movie clip image changes but with the same instance name.. when i select the save button the process is going as contacting server and then downloading and then idle..
even a file named snap shot is getting download in my local only.but when i select the save and open the jpeg file it is coming as a blank white.. but the movie clip size is same of mines.. i dont know why.. no image is there in tat.. only a white space is there.. can you tell me why and also i want that file not to save but to save in a tmp folder which we can take them later using post method from php.. plz help asap..

is false.. when i target it directly in the browser.. I gett this echo'd/printed to the screen: success=1

So I kniw it is there, and working.. when I try this on other applications it seems to work.. but when trying to use it on a 'bigger' .jpg (bitmap) type image..it doesnt work.. I have tried fast scan 7 default settings as well..

I just cant even get the image to be created.... (not worried about the security SAVE AS dialog box part)

so if anyone bothers to read this tut/section anymore.. and ideas/tips on how to start debugging would be great.

Thanks

Posted by: xl97 on February 9, 2009 10:18 PM

ok..I have tried testing over the last day or so...

its NOT something on my end (that I know of).

it 'seems' to be the 'image' (data) you want to export..

Summary:

I upload an image.. move it/edit it..etc..etc..try to save it..

if I upload/use an image is more like clip art or gradients.. (like a simple button or something).. it will work just fine..

has anyone used this on larger, more detailed images? like peoples faces/hair? like I said, it works fine if I upload/use an image that is more clip art.. simple/solid colors..

any ideas/tips? maybe a setting tweak?

Thanks

Posted by: xl97 on February 10, 2009 07:09 PM

I don't know why it fails for you but it might be a server-side problem. Maybe it is a memory overflow. Did you enable logging inside the PHP script? Maybe GD is producing an error in the last step where the JPEG is created - have you tried to output a BMP? The BMP format does not require GD so if that works the problem might be GD.

I know very little PHP.. but I think I have (some what) control on tweaking it with my current host.. so any ideas you have is really appreciated. It might be a server side problem.. as when I try to export small..or non-detailed images/objects.. it seems to work fine...

Im not sure what I should be doing or checking for.. I will peek at the PHP script..and enable the logging.. see if that can provide some help?

I have set logging = true ($LOGGING = true;)

I even tried setting the PHP memory limit to be 32MB

but Im not sure where to even check the logs? (sorry)..lol

I will try to use .bmp as the extension...

update re: .bmp.

It does complete.. and I get the prompt to save the .bmp.. however it cant be opened by anything..

Windows Pic/Fax Viewer says: Drawing Failed.
When trying to open it in Photoshop, It gives me a Error as well..

TO save as a .bmp.. is there any special line/settings I need to use?

Currently Ive just been doing this to get a .bmp (change the extension, literally)

Anybody found a simple way to retain transparency from PNGs yet? (using this class or any other?)

Posted by: mitch on April 4, 2009 04:14 AM

Hi there,
First off, thanks so much for the post and files for this. It's something I was searching for online!

I have a question though, I am making a website that allows the user to paint a picture. At the end I want to be able to take a snapshot of the picture and save it to a database, very similar to the original example of your demo http://www.quasimondo.com/archives/000572.php I do not want to take a snapshot of what the webcam is recording. How do I do this? I know there is probably a very simple solution! I would really appreciate any help! I'm an idiot!!

I understand that it is tedious to go through my answers to the previous question in the comments, but if you press CTRL-F and enter "draw(" into the search box you will find several answers to that question. In short: instead of the camera you simply draw the holder clip which holds your painted picture into an empty bitmapData and save that bitmapdata.

I just wanted to say a big thankyou! I know it is probably frustrating for you since the answer was there in front of me! But for some reason I could not figure it out at all! It was driving me mad, but I am sorted out now. Thanks so much for your help, and for this code! :)

I can see it outputs the information on the output panel in Flash, but I need to take the url (that links to the image ive captured in the TempFiles) it outputs and send it in an email to myself along with the users details.

Is there a way that I can do this? Or as Ben says above, send the image via email?

If you want to send the image url or the image itself to an email adress the best place to do this would be inside the bitmapexporter php script, but that would mean you have to read and understand the code in order to change it.

The easier way would be to write a second separate php script that you simply post the info that the "saved" event gave you to. If you google for "send image by email with php" or "send email with php" you will find tons of examples and libraries.

First of all, great Class! Really nice piece of coding.
I am, however, having a problem on some browsers/OS's...

I know this has been posted before, but the fix you recommended isn't working for me. It's the ERROR: [onImageHandle] HTTP Error.

I've set $KEEP_TEMP_FILES = true; but still not getting any love on the MAC with FF or Safari, and even on certain PC's running the same config as I am, and it works for me... PC, XPpro, FF... any clues?

i find another php4 (4.4.4) machine and our application doesn't work. do you have any idea, where to check in the AS script? it runs perfectly on one machine (apache with php 4.4) but not on other servers, the installation is absolutely the same...

who writes the tmp file? flash or php?
hm, maybe the stream will be stopped by one of them?? bitmapExporter knows the correct filesize and return a file "created". the file ist exactly 48955 Bytes all the time...

I already download your code and try to use it for my work. Just a question, for PHP stuff, i have to code it on my own to make this things work. Right? Sorry for this question, because i'm not familiar with php.

I'm trying to use the BitmapExporter to export multiple images automatically, one after the other. The problem I've run into is that after successfully exporting the first image, the status seems to stay in "retrieving" forever, without ever returning to the "idle" status. I've set dontRetrieve=true, and I'm listening to the "saved" event. I don't use the start button, I use the XML onLoad to start the export process automatically.

The function "if (BitmapExporter.getStatus() == "idle") {... will never return true after I've exported the first image, so it never is able to move on to the next images for export.

An update to my previous post: I've been able to manually reset the status to idle after it creates the first image, but it throws a seperate PHP error. For whatever reason, the exporter doesn't seem to be ready to handle a second image after exporting the first. Is there something other than using the reset function to make it ready to export a second image?

Pressing the save button multiple times successfully creates a new image each time, but I'm looking for a more automated solution to create a sequence of images.

Basically I could really use any ideas you have for creating a sequence of images, rather than just one.

Well, this might be an issue with the dontRetrieve mode. I haven't looked at my code but it sounds reasonable that a manual reset is required to set the status back. But as you write you are doing that already so I'm not sure why your PHP script doesn't like that. Are you using the reset() function?

thanks sharing your code! your BitmapExporter is an excellent alternative for those of us with a need create bitmap files but don't know AS3.

i've been able to integrate BitmapExporter with fair success but i keep hitting my head on one issue: for whatever reason, i absolutely cannot retrieve the "uniqueID" and pass it to a string in my fla.

i've tried every example here including an [otherwise reliable] echo from the php followed by a sendAndLoad script. nada. value returned is always undefined.

if you would, what is the simplest way to get the equivalent of something like: myFileName = uniqueID within an fla?

the idea is to pass the string to a simple getURL for later downloading.

many thanks!

-mark

Posted by: mark on December 17, 2009 05:38 PM

hey mario,

i've created [what so far appears to be] a reliable workaround for getting a "Save as" dialogue box in AS2 using a little PHP.

// NOTE: the private var "uniqueID" was changed to public in the original AS
};

once your new bitmap is ready to be downloaded, make a call to "saved()" followed by a call to "launchSaveAsDialogue()".

launchSaveAsDialogue() passes the filename to _popup.php (below) which in turn launches the "Save as" dialogue pop-up.

<?php

// save as "_popup.php"
// tested with latest versions of MSIE. FireFox and Opera
// this file must be saved in the same folder as the file(s) to be downloaded.
// if you're on apache don't forget to do a CHMOD 755 to this file once you copy it to your server.

There is a bold notice in the article, which I repeat here for your convenience: [Important Notice] due to a non-backward compatible change by Adobe in Flash Player 10 security model the default behavior of BitmapExporter - popping up a file browser after the saving has completed - is not possible anymore and will create a security error. I currently do not have time to change the class to accommodate for that problem, but fortunately it is not that difficult to work around it. Follow the instructions in this blog post: http://bit.ly/9PXKPV