May 28, 2007
Saving JPEGs or PNGs with Flash 8 Revisited

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:

BitmapExporter 2.2 Demo

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.

You can download BitmapExporter 2.2 here. The license conditions are:

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:

"[Insert your work title here] uses BitmapExporter by Mario Klingemann"

If you cannot comply to this rule please contact me for a special permission.

COMMERCIAL USE:
The use of the BitmapExporter package is NOT AUTOMATICALLY FREE for all commercial works or services. If you are able to show the follwing attribution line along with the work:

"[Insert your product title here] uses BitmapExporter by Mario Klingemann"

there is no license fee though it would be better for your karma if you shared a tiny amount of the money you get paid for this job with me.

If you do not want to or are not able to show the credit line the one time license fee is EURO 250.- per site/product.

Please contact me for special agency/studio conditions regarding licensing for multiple sites/products/clients.

Posted at May 28, 2007 02:37 PM | Further reading
Comments

Hi Mario,

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).

Posted by: Erik Lembke on May 28, 2007 09:12 PM

This class saved my life! Thank you very much Mario. I am gratuful.
This is perfect. The only problem is speed. I hope a helpful thing is done in AS3 as a guide soon.

In this exammple it takes 20 seconds to save the picture here.
When I upload the exammple to my paid server, it takes 40 seconds...
Ouchie !!

Posted by: Salvador on May 29, 2007 01:01 AM

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?

Thanks,
John

Posted by: John on May 29, 2007 05:12 PM

Mario,

Interestingly enough, I needed to do this just recently. I found some idiosyncrasies that may optimize performance:

http://lukesh.wordpress.com/2007/04/04/flash-8-bitmapexporter-class/

We actually wrote a C# server-side ashx to parse the base64 back into a jpg, which was fairly easy.

Posted by: Francis on May 29, 2007 05:54 PM

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.

Posted by: Mario Klingemann on May 29, 2007 06:14 PM

Mario,
It wasn't the "BitmapExporter.asp" file as much as it is the "BitmapExporterDemo2.fla" file that we can't open. Is there any reason why the "demo" file would not be flash 8 and possibly be CS3?

Thanks,
John

Posted by: John on May 29, 2007 06:36 PM

I have saved BitmapExporterDemo2.fla once more as a Flash 8 document and exchanged it in the zip - please re-download the archive and test if it works now.

Posted by: Mario Klingemann on May 29, 2007 07:44 PM

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

Posted by: Adam on May 30, 2007 01:04 AM

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.

Posted by: Mario Klingemann on May 30, 2007 11:15 AM

Adam, have a look at
http://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.

Posted by: Mike Duguid on May 30, 2007 03:23 PM

That's an excellent find, Mike! Thanks for sharing this.

Posted by: Mario Klingemann on May 30, 2007 03:37 PM

Mike - I just tested your business card demo, but unfortunately IrfanView gives me a "can't read header" error for the downloaded jpeg.

Posted by: Mario Klingemann on May 30, 2007 03:40 PM

I did this gizmo a few years ago.. I noticed right now It's broke, but I should have fixed it now .. try again please :)

Posted by: on May 30, 2007 04:23 PM

The necessary code in php btw:

$handle = fopen($myJpg, "r+");
fseek($handle, 13);
$dpiData="\x01\x01\x2C\x01\x2C";
fwrite ($handle, $dpiData);
fclose($handle);

Posted by: Mike Duguid on May 30, 2007 04:26 PM

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.

Posted by: Mike Duguid on May 30, 2007 04:28 PM

I've retried with the updated business card thing and can confirm both irfanview and photoshop report 300dpi

Posted by: Mike Duguid on May 30, 2007 05:42 PM

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?

Posted by: Andrew Paul Simmons on May 30, 2007 07:02 PM

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.

Posted by: Mario Klingemann on May 30, 2007 07:16 PM

I am trying to get the demo to work. Do I need to do something special with permissions or something?

When I click save, it shows "Initializing" for a few seconds, then the timer will just tick away indefinitely.

Please give me some guidance here.

Posted by: Jay on June 1, 2007 04:28 AM

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.

Posted by: virtualPK on June 1, 2007 04:20 PM

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

Posted by: Salvador on June 2, 2007 05:20 PM

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.

Posted by: Mario Klingemann on June 3, 2007 01:11 PM

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

Posted by: Antnio Alves on June 4, 2007 05:39 PM

Antnio: 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.

Posted by: Mario Klingemann on June 4, 2007 05:57 PM

Hi Jim. Photos i received. Thanks

Posted by: Bill Compton on June 5, 2007 12:28 AM

Hey all

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?

Posted by: Lee Kulberda on June 6, 2007 01:43 PM

Is it possible to add exif data to jpg's? I mean, at least date information. Thanks

Posted by: Zoilo on June 7, 2007 06:32 PM

very nice, you need to update to AS3, and see real power.
but so so work.
Ok, take care Quasimodo from Notre Damme.

Posted by: god on June 8, 2007 10:11 AM

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

Posted by: al flores on June 14, 2007 01:18 AM

How do i implement this step by step. I just think it would help people implement quickly.

Posted by: jay on June 14, 2007 08:14 PM

This is great, i been looking for this for months
Thanx

Posted by: on June 18, 2007 04:02 PM

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?

Posted by: Kevin on June 19, 2007 10:28 PM

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.

Posted by: Mario Klingemann on June 20, 2007 06:52 PM

Actually I figured out a way just by modifying your existing code. It may break some other things but works for what I need it to do:

-added a filepath:String param to saveBitmap Function in AS class (e.g. "../images/saved_jpgs/")

-pass that param to PHP via the loadvars (service.filepath = filepath;)

-use it in PHP instead of the $RELATIVE_URL to define the path for both the tmp file and the resulting jpg (
case "save":

$width = $_POST["width"];
$height = $_POST["height"];
$uniqueID = $_POST["uniqueID"];
$filename = $_POST["filename"];
$filepath = $_POST["filepath"];
$quality = $_POST["quality"];

$fp = fopen( $filepath.$tempFileName, "wb" );
)

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.

any thoughts?

Posted by: Kevin on June 20, 2007 08:28 PM

Have a question. In flash I am getting an I/0 error when trying to save. The save window pops up but nothing saves. I get the error that it cannot find file.

What I noticed is the php is appending &delete=1 onto the name of the image in the temp folder. How do I fix this?

BitmapExporter_Tempfiles/a71c989b3de9bb279967e3d68722b4dd.jpg&delete=1

Posted by: jay on June 21, 2007 10:55 PM

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.

Posted by: Mario Klingemann on June 22, 2007 02:36 AM

Jay - you have the same problem as the one further above on June 4 and I haven't yet figured out what's causing this. To temporarily fix this use:

BitmapExporter.deleteAfterDownload = false;

Posted by: Mario Klingemann on June 22, 2007 02:40 AM

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?

Posted by: alan on June 22, 2007 02:43 PM

Mario - I would like to purchase a License. Could you send payment details to me?

brett (AT) neo-pangea (DOT) com

Thanks!
Brett

Posted by: Brett on June 22, 2007 04:58 PM

@Alan: I wonder if it is maybe a glitch in the cleanUpTempFolder() method. So for testing you could try to uncomment line 601 and 607:

readfile( $file );
//if ($deleteFile) while(!unlink( $file ));
} else {
if ($LOGGING) error_log($file." does not exist", 3, $RELATIVE_SAVEPATH."be_log" );
exit();
}

//cleanUpTempFolder();

Posted by: Mario Klingemann on June 22, 2007 08:37 PM

@Brett: the license conditions can be found in the source code, but I've also just sent you a mail. Thanks!

Posted by: Mario Klingemann on June 22, 2007 08:46 PM

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:

Error opening URL "http://www.3wme.com/BitmapExporter.php?mode=download&name=ce402baef583b8d81f03b4878f23ecd8.jpg"

However I set the path to :
BitmapExporter.gatewayURL = "http://www.3wme.com/tests/BitmapExporter.php";

so somewhere the path is getting altered?

Posted by: alan on June 22, 2007 09:28 PM

I hard coded in the $DOWNLOADURL and it works fine. I cant see how there could be a bug altering the gatewayurl, perhaps $_SERVER['SERVER_NAME'] is getting an odd value from my php set-up?

Posted by: alan on June 22, 2007 09:50 PM

alan: Did you already try to change the whole line to
$DOWNLOADURL = "http://www.3wme.com/tests/BitmapExporter.php?mode=download&name=";

Posted by: Mario Klingemann on June 23, 2007 01:33 AM

Mario : yep, thats what I did, and it works. $_SERVER['SERVER_NAME'] seems to return the root folder?

Posted by: alan on June 23, 2007 11:41 AM

Mario -

"Kevin: ... Under no circumstances execute this command: $fp = fopen( $filepath.$tempFileName, "wb" ); without prior checks."

Duly noted - and eventually those checks will be in place. Thanks for the advice.

Posted by: Kevin on June 25, 2007 03:39 PM

Whow... very nice.

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.

thankz!

Posted by: walter on July 5, 2007 11:44 AM

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.

Posted by: Mario Klingemann on July 5, 2007 07:12 PM

Hey Mario

I've integrated your stuff and it's awesome, the only problem now is that after i saved the file, it 'sometimes' got corrupted, but the file at the server remains fine.

Just wondering if anyone has encountered a similar problem and has a solution to fix this.

Thanks,
Mars

Posted by: marspark on July 13, 2007 08:47 AM

Hi Mark,

which save mode are you using? And what kind of corruption is happening exactly? Is there a visual glitch in the image or does the image not open at all?

Posted by: Mario Klingemann on July 13, 2007 12:41 PM

Hey Mario,

I use .jpg and it just says the system can't open the file because it seems to get damaged or corrupted. On Mac, it won't let you open the file. On windows, it'll open as a completely blank file.

Regards,
Mars

Posted by: marspark on July 14, 2007 07:54 AM

With save mode I mean the compression method - e.g. "fastscan", "default" or "palette"

Posted by: Mario Klingemann on July 18, 2007 12:40 PM

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.

Posted by: Mario Klingemann on July 19, 2007 10:49 AM

And no, sorry for the confusion - you don't need getimage.php anymore - this is an old comment that I forgot to delete.

Posted by: Mario Klingemann on July 19, 2007 10:50 AM

Hey Mario,

I'm using "default", I've tried the "turboscan" but it still remains the same.

Posted by: Mars on July 19, 2007 12:33 PM

Hey Mario,

Can i control the resolution of the output image or its just 72 dpi or the default screen resolution.

thanks in advance

Alok

Posted by: AKJ on July 19, 2007 03:41 PM

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.

Anything I'm missing with setup?

Posted by: Luke on July 20, 2007 03:56 AM

What would I have to do if I wanted to use your Bitmap Exporter v2 for a commercial product ?

Posted by: The Flash Man on July 21, 2007 02:46 AM

The license conditions can be found above in the article and in the source code itself, but here you go:

COMMERCIAL USE:
The use of the BitmapExporter package is NOT AUTOMATICALLY FREE for all commercial works or services. If you are able to show the follwing attribution line along with the work:

"[Insert your product title here] uses BitmapExporter by Mario Klingemann"

there is no license fee though it would be better for your karma if you shared a tiny amount of the money you get paid for this job with me.

If you do not want to or are not able to show the text line the one time license fee is EURO 250.- per site/product.

Please contact me for special agency/studio conditions regarding licensing for multiple sites/products/clients.

If you want to know how you can send me the money, please send me an email to mario@quasimondo.com and I'll give you the details

Posted by: Mario Klingemann on July 21, 2007 03:08 AM

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.

Posted by: tod on July 25, 2007 09:46 AM

Did you already try to listen to the BitmapExporter "error" event and trace out the messages? You also can switch on logging in the php part and see what happens there.

In general I also recommend the "Tamper Data" add-on for Firefox (https://addons.mozilla.org/de/firefox/addon/966) which is a very useful tool when it comes to debugging client-server communication.

Posted by: Mario Klingemann on July 25, 2007 11:58 AM

Thanks for the info.

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.

Posted by: Mario Klingemann on July 26, 2007 01:28 PM

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:

http://www.quasimondo.com/scrapyard/BitmapExporter_v22.zip

Posted by: Mario Klingemann on July 26, 2007 02:25 PM

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

function saved( e:Object ){

trace("image URL: "+e.url);
trace("image filename: "+e.fileName); trace("image uniqueID: "+e.uniqueID); trace("sentBytes: "+e.sentBytes); trace("time: "+e.time);
trace("compressionRatio: "+e.compressionRatio);
}

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.

Posted by: Mario Klingemann on July 27, 2007 12:09 PM

Great job!

This is a very useful software.

Posted by: Haluk Akin on July 30, 2007 02:54 AM

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.

Posted by: Mario Klingemann on July 31, 2007 11:09 PM

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?

Posted by: Jorge on August 3, 2007 11:19 PM

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.

Posted by: Mario Klingemann on August 4, 2007 02:57 PM

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.

Again, it probably happens in 1 out of 50 scans (rough estimate)

Posted by: Jorge on August 7, 2007 01:44 AM

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.

Posted by: Mario Klingemann on August 7, 2007 02:00 AM

hi,

where put true for the argument dontRetrieve? in the bitmapexporter.as

thanks..

Posted by: carolina on August 7, 2007 08:09 AM

It is the last argument:

BitmapExporter.saveBitmap( bitmap:BitmapData, filename:String, mode:String = "default", lossBits:Number = 0, jpegQuality:Number =75, dontRetrieve:Boolean = false );

Posted by: Mario Klingemann on August 7, 2007 11:48 AM

I don't find where put this

BitmapExporter.saveBitmap( bitmap:BitmapData, filename:String, mode:String = "default", lossBits:Number = 0, jpegQuality:Number =75, dontRetrieve:Boolean = true );

is in the fla? or the as or the php?

thanks for always guide us with all this questions!!

Posted by: carolina on August 7, 2007 05:48 PM

Yes, it is in the fla. If you take a look at the code and the comments in the demo file you can see how it is suposed to work.

Posted by: Mario Klingemann on August 7, 2007 06:10 PM

Hi Mario,

Do you have any idea how can I show an image in a browser without saving it on the server?

thanks in advance

Posted by: greval on August 9, 2007 12:09 PM

greval: that question is a but vague I must say. Can you clarify that a bit? Where does the image originally come from? Has it been created by a user? Do you want to display it in Flash or in html?

In general an image has to have a url in order to be displayed in a browser which means it either has to be located on a server somewhere or on the user's harddrive.

Posted by: Mario Klingemann on August 9, 2007 12:29 PM

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.


Posted by: greval on August 9, 2007 12:51 PM

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.

Posted by: Mario Klingemann on August 9, 2007 01:04 PM

Mario, two issues that I think people might need help on.

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?

Posted by: Jorge on August 10, 2007 10:49 PM

Jorge:

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.

Posted by: Mario Klingemann on August 10, 2007 11:30 PM

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.

Thanks again Mario!

Posted by: Jorge on August 13, 2007 06:14 PM

hi mario, i have a question concerning transparency.

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 :-(

Posted by: dwieps on August 20, 2007 08:42 PM

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.

Posted by: Mario Klingemann on August 20, 2007 08:58 PM

well meaby with your MaskImage class ,i can create a work around.

i can already save the picture as a jpg

I only have to figure out how to save the picture like a blackandwhite gif

and then mix the 2 files in flash with your maskimage class.

Posted by: on August 20, 2007 09:48 PM

You can use the ColorMatrixFilter to turn the alpha channel into a b/w bitmap - I think it should work something like this (haven't tested it):

var cmf:ColorMatrixFilter = new ColorMatrixFilter([0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,255]);
var bwMap:BitmapData = rgbaMap.clone() // rgbaMap is your original map with alpha channel
bwMap.applyFilter(rgbaMap,rgbaMap.rectangle,new Point,cmf);

Posted by: Mario Klingemann on August 20, 2007 09:57 PM

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...

Posted by: andrew on August 22, 2007 09:48 PM

Both options are possible. By default the temporary images get deleted after they have been downloaded.

Posted by: Mario Klingemann on August 22, 2007 10:06 PM

What about exporting an MC with multiple dynamic MC's inside it as a jpeg? Is this possible? i.e., "flatten" the MC's contents into a bitmap and export it...

Posted by: andrew on August 22, 2007 11:14 PM

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.

Posted by: Mario Klingemann on August 22, 2007 11:24 PM

Hi,

I get this message..

ERROR:[onImageHandle] WARNING[2] set_time_limit(): Cannot set time limit in safe mode (0%)

any idea? why or what line a I have to reconfigurated?

Posted by: martin on August 22, 2007 11:51 PM

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.

Posted by: Mario Klingemann on August 22, 2007 11:58 PM

Hi,

I get again another message [onAddPixelBlock] HTTP error 0 ERROR: [onAddPixelBlock] HTTP error 0

Posted by: Martin on August 23, 2007 04:03 AM

Does that happen every time? How big is the image you are trying to save? This might be your server timing out. Unfortunately in that case I cannot capture that bug if your server runs ins safe mode.

Posted by: Mario Klingemann on August 23, 2007 11:17 AM

Hey Mario

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?

Posted by: Sooty on August 23, 2007 04:55 PM

Hi Mario,

Great work. Just wondering - Are you aware of anyone who has done .NET port of your PHP stuff, or who has this running in .NET?

Thanks,
Dan.

Posted by: Dan on August 24, 2007 10:18 AM

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 ;-)

Posted by: Mario Klingemann on August 24, 2007 06:49 PM

Hi Mario,

thanks for the script, but I run into a problem that said '[onImageHandle] not defined in Flash, any insight?

Posted by: ken on August 25, 2007 09:48 AM

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.

Posted by: Mario Klingemann on August 25, 2007 01:33 PM

Hello Mario
This is an execellent work done.

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.

on the other hand it works great with width=250 n height=180;

But how can i generate images with 800 X 600 ??

Posted by: Inder on August 28, 2007 03:39 PM

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.

Posted by: Mario Klingemann on August 28, 2007 03:47 PM

Thank You Mario
for replying and giving me the solution.It is working now.

now Last question.
is there any possibility to generate .wmf image or any other vector format image from it.

Thank you so much.
Inder

Posted by: Inder on August 28, 2007 06:44 PM

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.

If you are creating a drawing tool you could generate your own SVG data file for export. You could use this demo of an actionscript SVG renderer as a starting point: http://www.flash-creations.com/notes/sample_svgtoflash.php

Posted by: Mario Klingemann on August 28, 2007 07:02 PM

Thank you Mario

for replying and giving me a direction.

Thanks again. :)
Inder

Posted by: Inder on August 29, 2007 05:14 PM

Is there anyway to output AS 2.0 images to 300 dpi without GD?

thank you,
Emma

Posted by: Emma on September 5, 2007 06:04 PM

There is probably a way to add dpi information to the PNG that is produced on the server side, I just don't know how the specification for that is. So I can't promise you that this will be added soon.

For the moment you just have to open the exported bitmaps in Photoshop, go to "Image Size" and change the dpi number with the "resample image" checkbox off.

Posted by: Mario Klingemann on September 5, 2007 06:25 PM

Hi Mario,

Firstly, thanks for sharing with us this wonderful creation.

I done some testings on my side but unsure of what went wrong. I am able to save PNG but not JPG (it prompts me with Error:[onSave]undefined)

Is there something that I should adjust to get it right?

Thanks :)

Posted by: Johnson on September 10, 2007 08:13 AM

Hi Mario


Thanks for you time on this appllication, but i cant get past this error message when i press save.

ERROR: [onImageHandle] HTTP Error null

Posted by: JJ on September 11, 2007 04:33 PM

and here is the other error message

ERROR: IO error with file snapshot.png

Posted by: JJ on September 12, 2007 09:43 AM

I get the same error as JJ

"IO error with file snapshot.jpg"

Any help?

Posted by: andrew on September 18, 2007 08:19 AM

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.

Posted by: Mario Klingemann on September 18, 2007 10:53 AM

And I get the error "IO error with file snapshot.jpg"
Solved by changing line 172 - BitmapExporter.php (ver.2.2)
from: $DOWNLOADURL = "http://".$_SERVER['SERVER_NAME']."/BitmapExporter.php?mode=download&name=";
to: $DOWNLOADURL = "http://www.your-web-site.com/temp/BitmapExporter.php?mode=download&name=";
(full path to BitmapExporter)

Posted by: Flasher_007 on September 19, 2007 01:32 PM

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.

Posted by: Mario Klingemann on September 19, 2007 02:35 PM

Hoi Mario,

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.

Posted by: Bauke on September 20, 2007 04:04 PM

Forgot to say, I'm trying to export jpg

Posted by: Bauke on September 20, 2007 04:06 PM

And all the php specs can be seen right here:

http://81.173.116.152/php/phpinfo.php

Posted by: Bauke on September 20, 2007 04:23 PM

Hey there...really nice setup you have here.

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...

Posted by: Brandon M on September 27, 2007 05:55 PM

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.

Posted by: Brandon M on September 27, 2007 09:55 PM

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 ( / )

Sweet

Posted by: Brandon M on September 27, 2007 11:15 PM

can u tell me how i make the image background transparent. Please if any one do that please he can help me to make the image transparent

Posted by: amrit on October 3, 2007 01:09 PM

hello,

Any body can you help regrading the creation image of transparent in BitmapExporter_Tempfiles folder.

Please help me to chnage the image with back ground transparent

Posted by: Amrit on October 3, 2007 03:30 PM

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.

Is there any suggestion to overcome the problem.

Posted by: rajib on October 6, 2007 12:04 PM

Sounds to me like you draw the wrong clip to the bitmapdata. This is wrong:

var myClip.mask = maskClip;
bitmap.draw(myClip);

You have to draw the clip which holds both the clip and the mask - something like this:

var holder.myClip.mask = holder.maskClip;
bitmap.draw( holder )

Posted by: Mario Klingemann on October 6, 2007 12:22 PM

Mario, you make the comment: "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."

What are those?

Posted by: Jerry on October 8, 2007 03:22 PM

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:

ERROR: [onImageHandle] WARNING [2] error_log(../image/be_log) [function.error-log]: failed to open stream: Permission denied

the app is in: http://mono-studio.net/drawing-board/

I really don't know why and would be great if you can help.

Thanks in advance

Posted by: Keni on October 9, 2007 11:44 PM

Since you don't seem to use the default location and pathnames - have you update all the paths variables correct in the BitmapExporter.php file?

Posted by: Mario Klingemann on October 10, 2007 10:50 AM

Hi, Mario,

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.

: )

Keni

Posted by: Keni on October 10, 2007 04:07 PM

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.

Posted by: Mario Klingemann on October 10, 2007 04:29 PM

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.

Anyway, wish me luck and stay in touch

Keni

Posted by: Keni on October 10, 2007 09:12 PM

HI, Mario,

I have try the application online and got a error message from the server after I put the full URL as the Relative_Savepath.

the message was
failed to open stream httpwrapper does not support writeable connections.

I know is nothing to do with the BitmapExporter. But if I have to set up something on the server, what will it be?

Can you help? Please

Keni

Posted by: Keni on October 11, 2007 01:00 AM

hey mario, i'm getting "ERROR: [onSave] undefined"

what causes this error?

Posted by: matt on October 11, 2007 02:03 AM

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

thanks in advance
-matt

Posted by: matt on October 11, 2007 03:15 AM

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/"

Posted by: Mario Klingemann on October 11, 2007 11:01 AM

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.

Posted by: Mario Klingemann on October 11, 2007 11:04 AM

Hi, Mario,

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:

http://mysite.com/phpdirectory/imgdirectory/tempString.png can not be found. And therefore the server hang out and no image was save.

Sorry of keep bordering you. Thanks in advance.

Keni

Posted by: Keni on October 11, 2007 01:03 PM

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.

And "tempString.png" looks like a weird name for a file.

Posted by: Mario Klingemann on October 11, 2007 01:22 PM

Sorry, it may explain better in this way:

when Safari load the page:
http://mysite.com/phpdirectory/BitmapExporter.php?mode=download&name=3a32c9675643a63bb892dbfb4261a8b3.png

it turn out as a 404 error therefore, executed the download.

Keni

Posted by: Keni on October 11, 2007 01:34 PM

what php libraries does this require?

Posted by: matt on October 11, 2007 07:51 PM

matt: if limit yourself to PNG and BMP output it needs no additional PHP libraries. If you want JPEGs you will need GD.

Posted by: Mario Klingemann on October 11, 2007 08:43 PM

I am using this application in my local machine. It works fine. But while I am trying to upload the same to the server it fails to work.

I have checked all paths and they are correct. But the application is stopped while I want to run from server.

Is there any way out ?

Posted by: Rajib on October 12, 2007 05:06 PM

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?

thanks in advance
-matt

Posted by: matt on October 12, 2007 07:12 PM

do you have a suggestion regarding how much memeory the php should be alloted?

Posted by: matt on October 12, 2007 07:13 PM

Hi,

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()?

Posted by: Mario Klingemann on October 22, 2007 03:37 PM

her mario, your bitmap exporter is awsome,
I want it to save the file to the server only, and not to the users desktop, what section of code do I need to comment out?

thanks!

Posted by: Q on October 23, 2007 06:05 PM

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.

Posted by: Mario Klingemann on October 23, 2007 07:19 PM

hey mario,
i changed this
private var dontRetrieve:Boolean = true;
in the .as file

i couldnt find what the other users were talking about

BitmapExporter.saveBitmap( bitmap:BitmapData, filename:String, mode:String = "default", lossBits:Number = 0, jpegQuality:Number =75, dontRetrieve:Boolean = false );

was this in the earlier version?

Posted by: q on October 23, 2007 08:53 PM

You don't have to change anything in the Actionscript class file. You just have to use "true" as the last argument when you call the saveBitmap method:

var yourBitmapData:BitmapData = new BitmapData(640,480,false,0);
BitmapExporter.saveBitmap( yourBitmapData, "yourFilename.jpg", "default", 0, 75, true );

Can you see the "true" after that 75? That is the dontRetrieve switch.

Posted by: Mario Klingemann on October 23, 2007 08:59 PM

sorry i'm asking so many questions,

is that line in the fla file?
or is it somthing I need to add?

since I dont see it in the fla file, i'm guessing its an argument I need to access thats generated when the save function is called?

thanks mario

Posted by: q on October 23, 2007 09:14 PM

BitmapData.saveBitmap(... is the command that you use to save bitmaps. Have you read the comments in BitmapExporter.as and looked at the demo fla?

Posted by: Mario Klingemann on October 23, 2007 09:21 PM

got it, thanks for your time mario

Posted by: q on October 23, 2007 11:26 PM

Hi Mario,

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.

Any ideas?
Brian

Posted by: Brian on October 31, 2007 07:41 PM

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.

(just removed that "index" spam filter)

Posted by: Mario Klingemann on October 31, 2007 07:51 PM

THanks for the quick reply!

I'll try defining that index in php, or atleast not having the process halt on this error. Calling the webhost is a last resort :(

Thanks again,
Brian

Posted by: Brian on October 31, 2007 08:00 PM

Hello again Mario!

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!

Brian

Posted by: Brian on November 1, 2007 02:44 AM

Oh, let me just say one more time that I have this working fine locally and on other webservers, so I am fairly certain it has to be a PHP setting somewhere.

Posted by: Brian on November 1, 2007 02:46 AM

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.

Posted by: Insoloaccor on November 2, 2007 09:08 AM

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)

Anyone has any idea?

btw thank u mario for creating such an useful apps =)

Posted by: kelts on November 18, 2007 12:52 PM

The most common problems are:

- 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?

Posted by: Mario Klingemann on November 18, 2007 01:16 PM

Just discovered that server does not have GD installed.. gotta try it out ..

Thanks for the prompt reply!

Posted by: kelts on November 18, 2007 05:30 PM

Hi Mario
Thanks for the app, it works great.
I've been trying to write a function for 'on complete', but it's failing to get called - I'm doing it in evt.status like this using case "complete"

I need to flash a 'thanks' message when done - what's the best way of doing that?
Thanks for all your work
wil

Posted by: Wil on November 21, 2007 03:19 PM

Did you set the dontRetrieve argument to true? In that you will have to listen to the "onSaved" event instead.

Posted by: Mario Klingemann on November 21, 2007 03:30 PM

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?

thanks
wil

Posted by: Wil on November 21, 2007 04:16 PM

The absolute url to the saved image on your server will be passed in the event object of the onsaved event:

function onSaved( eventObj:Object ):void
{
trace( eventObj.url );
trace ( eventObj.fileName );
trace ( eventObj.uniqueID);
trace ( eventObj.sentBytes);
trace ( eventObj.time);
trace ( eventObj.compressionRatio );
}

Posted by: Mario Klingemann on November 21, 2007 04:34 PM

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.

I have the feeling I am missing something really rudimentary here.

Posted by: ernest on November 25, 2007 04:09 PM

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.

Posted by: Richard on November 28, 2007 10:52 AM

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.

Posted by: Mario Klingemann on November 28, 2007 12:35 PM

Thanks for your help Mario and the very quick response! I think I would be able to get that working now. Cheers.

Posted by: Richard on November 29, 2007 10:54 AM

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??

Posted by: wayne on December 7, 2007 08:52 AM

Hi Mario,

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

Posted by: Gus on December 12, 2007 12:11 AM

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.

my guess is (something like):
x = -thebitmapWidth/2;
y = -thebitmapHeight/2;
should work, but then again...

Posted by: Dr.Punchman on December 13, 2007 08:43 PM

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.


Posted by: Mario Klingemann on December 13, 2007 09:39 PM

Mario,
Thanks!
Actually that is exactly where I have been for the past few hours (ha!).

The Matrix seems to be the trick. Figuring out the Matrix is putting a cramp in my brain. I'm running a bunch of small tests, and am getting closer for sure!
Keep up the good work!

Posted by: Dr.Punchman on December 13, 2007 10:12 PM

MARIO YOUR BITMAPS BitmapExporter ROCKS. but i got a problem, when a use it de loader line stay in 95% and de flash console display this error

[onAddPixelBlock] WARNING [2] fopen() [function.fopen]: Unable to access BitmapExporter_Tempfiles/f94492623e89fc01b0e2e56cce8d2ac6<script src=\"
.tmp

HOW I CAN REPAIR THIS????

HELP ME PLEASE..

Posted by: Antadd on December 23, 2007 02:52 AM

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.

Posted by: Mario Klingemann on December 23, 2007 01:53 PM

Mario Thanks. I think my problem is my free web space, because i used the BitmapExporter in my local and woks's fine.

I need a free web space with file permmision can you help me with that??? Kwon you where i can find a good free web space???

Gretings

Posted by: Antadd on December 23, 2007 03:56 PM

dear mario
i am not familiar with classes. i extracted the files but i do not no how to implement the script in my fla.
the demo is excellent but i am unable to use it.
ehud

Posted by: ehud on December 25, 2007 07:37 PM

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

Posted by: ehud on December 25, 2007 07:50 PM

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.

Posted by: Mario Klingemann on December 27, 2007 02:56 PM

Antadd: I cannot give you a specific recommendation for webspace but I'm pretty sure that there is no free service which allows you to run your own PHP scripts.

Posted by: Mario Klingemann on December 27, 2007 02:59 PM

thank you mario.
sorry if i bother you.
idid everything opk but i receive "fopen (bitmapexport_tempfiles/1 "......"failed to open stream: permission denied"
can i overcome this problem?

Posted by: ehud on December 28, 2007 01:09 PM

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.

Posted by: Mario Klingemann on December 28, 2007 05:45 PM

can you please give me very simple php which will rename the imageID?
thanks

Posted by: udi on December 28, 2007 08:37 PM

http://www.google.com/search?q=php+rename+file

Posted by: Mario Klingemann on December 29, 2007 04:38 PM

Hi hi,
When i change BitmapExporter.gatewayURL= http://localhost/... to BitmapExporter.gatewayURL= http://mysite.com/...
it's not work????
T.T

Posted by: w2art on January 16, 2008 10:10 AM

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.

Posted by: Mario Klingemann on January 16, 2008 12:14 PM

Hc hc i test on localhost good, but i upload on host it can't save picture and i don't see error.
Link here
http://w2art.uni.cc/index.html

Posted by: w2art on January 17, 2008 07:41 AM

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.

Posted by: Mario Klingemann on January 17, 2008 10:06 AM

Hi i have been trying to use bitmapexporter class to capture a .linestyle user drawing. I am getting a error of

[onImageHandle] ".urlencode($message) );

what does this error message mean?

Posted by: Raf on January 18, 2008 12:46 AM

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.

Posted by: Mario Klingemann on January 18, 2008 09:26 AM

Sweet, I got it to work. I am now getting an IO error but the temp file is what I need as the final output of the code.

Posted by: Raf on January 18, 2008 02:43 PM

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?

Posted by: Raf on January 21, 2008 06:59 PM

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?

Posted by: Eli on January 21, 2008 09:18 PM

hello
i gut your webcam snapshot script (www.quasimondo.com/schnappschuss1.php) but cant make it work
please, if possible, help explaining what need to do to make it work

thank you very much

Posted by: Avir on January 28, 2008 12:46 PM


- .

Posted by: DildEldeseert on February 6, 2008 07:35 PM

Hi Mario,

Great app. Quick question, could you let me know in what files I have to change the URL gateway for uploading the files to another server than localhost?

From what I can tell, you need to change the path in the main .fla, Bitmapexporter.php and the .as file in the com folder.

Thanks,

Dan

Posted by: Dan on February 11, 2008 09:22 PM

Of course you don't have to change anything in the classes or the php. You just say this in your code:

BitmapExporter.gatewayURL = "http://www.yourserver.com/somewhere/BitmapExporter.php";

Posted by: Mario Klingemann on February 12, 2008 11:55 AM

In Flash run OK. But in Internet Explorer have a error ERROR: [onImageHandle] HTTP Error null.

Posted by: Edwin Insuasty on February 17, 2008 09:28 PM

Hi Mario,

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:

---->transparent outline PNG movie clip called "coloring_page" (what the pens, pencils, crayons, markers, etc... appear to draw on)

---->Non transparent Flash shape rectangle movie clip called "canvas" which is where the actual drawing takes place.

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.

You can check out my implementation here:

http://www.dadalicious.com/colbook/

I know that I am probably pushing it beyond what it was designed for, so I'll understand if you don't want to bother, but any help you could give would be appreciated.

Posted by: Brian Holbrook on February 24, 2008 08:26 AM

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.

Posted by: Mario Klingemann on February 24, 2008 05:27 PM

Mario,

Thank you so much. I've been struggling with this for days (I'm more of an animator than a coder). I appreciate the fast reply. I'm sure with the help you have provided I can get it working now.

Posted by: Brian Holbrook on February 24, 2008 09:11 PM

Hello Mario,
Its a tremendous work that you have done. Really appreciative! And really nice coding.

I am not a PHP programmer, just an intermediate AS2 coder and Flash Animator. I am working on a test project in which i had to put the option for printing, exporting as bitmap and emailing.

Do you have suggestions regarding the emailing of exported bitmap? Is it possible that we add another module next to the download/save part where the exported bitmap just send to an email address ??

Any suggestions and comments??

Thanks a million Mario!
Best Wishes,
Aamir

Posted by: Aamir on February 28, 2008 12:09 AM

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.

Posted by: Mario Klingemann on February 28, 2008 11:58 AM

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 know it sounds stupid but i am stuck here, and i need help :(

Please advice
And thanks a lot for your advice and help.
Aamir

Posted by: Aamir on February 29, 2008 07:06 PM

hello mario,

im experincing some problems putting these file together.

could you tell how they should be uploaded to a server. many thank
james

Posted by: james allen on March 7, 2008 04:20 PM

hi

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

regards

Atif

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

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?...


thanks


Karim

Posted by: Karim on March 28, 2008 04:17 PM

Just found the bug - and my apologies - its in my code...

Posted by: Karim on March 28, 2008 04:23 PM

Hi , i need to know can we save the image as 300 DPI

and how ?

Thanx

Posted by: bilal on April 3, 2008 01:34 PM

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?

Posted by: Rorro on May 1, 2008 12:22 AM

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?

Posted by: Rorro on May 1, 2008 12:23 AM

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.

Posted by: Mario Klingemann on May 1, 2008 01:37 AM

Hi Mario,

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?

Posted by: templar on May 4, 2008 09:57 PM

@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.

Posted by: Mario Klingemann on May 5, 2008 12:31 PM

Mario,

This is an excellent contribution to the community. Thank you.

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?

Thanks.

Posted by: mike on May 8, 2008 08:47 PM

Mike,

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.

Posted by: Mario Klingemann on May 10, 2008 12:02 AM

Hi Mario,

I'm getting Error: OnAddPixelBlock notice 8: undefined offset: YYY (YYY=random number).

Can you help me?

Posted by: Noah on May 11, 2008 03:42 PM

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

Posted by: Mario Klingemann on May 11, 2008 03:59 PM

Hello Mario,

after several days of testing I still can't find the error... I changed my php.ini file to both of the settings...
So anyother ideas?

Posted by: Noah on May 19, 2008 07:36 PM

Did you also restart PHP / your webserver after changing php.ini?

Posted by: Mario Klingemann on May 19, 2008 08:01 PM

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!

Posted by: Stephen Scott on May 27, 2008 05:26 PM

I have restarted many times and checked the php.ini file but still on add pixel error. Strangely it works completely when you draw nothing but when you draw something it returns the notice.

Thanks in advance!

Posted by: Noah on June 7, 2008 03:51 PM

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.

Posted by: Mario Klingemann on June 18, 2008 10:22 AM

Sorry to bring up the old stuff (again).. but I cant seem to get past this 'BUG' no matter what I've tried.

in the .swf I have set my URL:
[code]
BitmapExporter.gatewayURL = "http://www.dmstudios.net/demos/imageSave/BitmapExporter.php";
BitmapExporter.deleteAfterDownload = false;
[/code]


turned OFF the clean-up (deletion) after.. to ensure the image doesnt get wiped before the download.

I have read here and changed the PHP file accrodingly

I either get the server is busy/not responding or the an IO error:

contacting server
sending
retrieving
downloading
IO error with file snapshot.jpg
ERROR: IO error with file snapshot.jpg
idle


with this in PHP script:
[code]$DOWNLOADURL = "http://www.hardcoded.com/demos/imageSave/BitmapExporter.php?mode=download&name=";[/code]

contacting server
Connection Timeout - no response from server
ERROR: Connection Timeout - no response from server
idle


with this in PHP script:
[code]$DOWNLOADURL = "http://www.hardcoded.com/demos/imageSave/BitmapExporter_Tempfiles/";[/code]

contacting server
Connection Timeout - no response from server
ERROR: Connection Timeout - no response from server
idle


with this in PHP script:
[code]$DOWNLOADURL = "http://".$_SERVER['SERVER_NAME']."/demos/imageSave/BitmapExporter.php?mode=download&name=";[/code]


any tips on a direction I search on?

thanks

Posted by: xl97 on June 24, 2008 12:08 AM

hi-

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?

Is this correct?

thanks

Posted by: xl97 on June 24, 2008 05:12 PM

hi xl97,

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()

Posted by: Mario Klingemann on June 24, 2008 05:35 PM

Thanks Mario-

I had a test working (no clean up weather automatic or after a day).. not sure how to go about debugging that.. AS it more my thing than PHP..lol

also... when I finally implemented (trying) into my demo.. I get the save (ONLY RGB or PALLETE settings)..

and I am prompted for a download, however when I look at image on desktop..its just white?

the clip that I am trying to capture/take snapshot of is a parent clip that has several nested clips that have been dragged over the stage..etc

Thanks

Posted by: xl97 on June 26, 2008 10:47 PM

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

PASTE:
sending
[onAddPixelBlock] NOTICE [8] Undefined offset: 12
ERROR: [onAddPixelBlock] NOTICE [8] Undefined offset: 12
idle


usually of that nature... what settings can I use to by pass this? and get the main focus of my stage in the 'capture'? and reliably sent to php for a render?

thanks

Posted by: xl97 on June 26, 2008 10:54 PM

Hiya Mario-


overview/summary: (for perspective)

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?

I hoepe this makes sense? I think someone above commented on it?

Is this a TUT/POST I should be trying to add into this?

http://www.quasimondo.com/archives/000670.php

(got some time tonight to work on things.. so Im hoping someone is around)

thanks again.

Posted by: xl97 on June 27, 2008 12:30 AM

well - the method described on that page is AS3, but in priciple this should also work with the AS2 getBounds method. You only have to calculate width as xMax - xMin and height as xMax- yMin.

Posted by: Mario Klingemann on June 27, 2008 12:43 AM

LOL..

ok.. I guess I'll give it a once over.. seems little bit at my 'capping point' with AS... and I havent touched AS3 once yet..(unfortunately)

and not to experienced with getBounds() or the second param of: new Matrix..

I guess I can google on usage? any tips or advice are appreciated.

thanks

Posted by: xl97 on June 27, 2008 03:45 AM

HI Mario-

(me again)..sorry I cant this to work..and its driving me nuts.. so I keep chipping away at it.

From your post..are you saying to do this then:

var bounds_obj:Object = mainParts_container.getBounds(this);

var snapshot:BitmapData = new BitmapData((bounds_obj.xMax - bounds_obj.xMin), (bounds_obj.yMax - bounds_obj.yMin), false);

snapshot.draw(mainParts_container);


and thats all I need? I cant seem to get it to work from trying both snippets of code here:
http://www.quasimondo.com/archives/000670.php

even though it is AS3.. I tried to make the matrix = new Matrix and pass that object in..as well as your way (which I guess I dont understand much when looking at it)

Posted by: xl97 on June 27, 2008 04:34 AM

this is what I tried as my last result (stripping out any matrix junk again)

var bounds_obj:Object = mainParts_container.getBounds(this);
for (var i in bounds_obj) {
trace(i+" --> "+bounds_obj[i]);
}
var snapshot:BitmapData = new BitmapData((bounds_obj.xMax - bounds_obj.xMin), (bounds_obj.yMax - bounds_obj.yMin), false);
//var snapshot:BitmapData = new BitmapData(850, 500, false);
//var snapshot:BitmapData = new BitmapData( int( bounds.width + 0.5 ), int( bounds.height + 0.5 ), false );
snapshot.draw(mainParts_container);
BitmapExporter.saveBitmap(snapshot, "save.jpg", "palette", 0, 50, false);


(I wish I could edit instead of making a new post...sorry)

Posted by: xl97 on June 27, 2008 04:41 AM

sorry-

update.. it IS in-fact working (sorta)

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

thanks

Posted by: xl97 on June 27, 2008 04:48 AM

The trick of using getBounds() in this case is to get the bounds of the clip within itself. Which means you have to pass the clip as the reference:

Wrong:
var bounds_obj:Object = mainParts_container.getBounds(this);

Right:
var bounds_obj:Object = mainParts_container.getBounds(mainParts_container);

Posted by: Mario Klingemann on June 27, 2008 10:20 AM

(I thought I replied to this earlier this a.m.)..

anyways.. yes I tried that as well.. I get the same results.

[code]
var bounds_obj:Object = mainParts_container.getBounds(mainParts_container);
for (var i in bounds_obj) {
trace(i+" --> "+bounds_obj[i]);
}
var snapshot:BitmapData = new BitmapData((bounds_obj.xMax - bounds_obj.xMin), (bounds_obj.yMax - bounds_obj.yMin), false);
snapshot.draw(mainParts_container);
BitmapExporter.saveBitmap(snapshot, "save.jpg", "palette", 0, 50, false);
[/code]

I still get a white image because the nested clip(s) are not starting in the uppder left hand corner (X:0/Y:0)

in my example above.. the .draw() has no second parameter.. is it needed? I would assume so if this 'matrix' parameter is supposed to update/translate?

sorry to keep beating a dead horse here.. your AS3 example doesnt quite make sense to me..and the second post is only a few lines..when I merge I get errors. :(

Posted by: xl97 on June 27, 2008 05:25 PM

Ah I see. Well, the matrix parameter is the most important part of this whole process. So you have to say draw( mainParts_container, new Matrix(1,0,0,1,-bounds_obj.xMin,-bounds_obj.yMin));

Posted by: Mario Klingemann on June 27, 2008 05:47 PM

Yeah when I tried that I get this error:

ERROR:
saveBitmap Arguments are not correct
ERROR: saveBitmap Arguments are not correct

I see now that the values are negative.

I believe that to be my error.

Thanks a ton Mario. :)


Posted by: xl97 on June 27, 2008 07:06 PM

Hey Mario-

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?

The reason I ask is because I see images days older in there still...

Thanks

Posted by: xl97 on July 4, 2008 05:08 PM

hi-.. anybody else maybe have some info on the auto clean-up portion? or some insight on those errors Im seeing my 'error_log' binary file?

thanks

Posted by: xl97 on July 11, 2008 04:59 PM

Hello Mario,

Some people have asked, but so far not seen the answer (excuse me if you have already been posted). Can you help us to save the image from webcam on server in a size larger than 160x120?

Thank you.

Posted by: Carlos Eduardo on July 16, 2008 05:42 AM

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?

Posted by: xl97 on July 24, 2008 07:18 PM

unfortunately.. I dont know much PHP..and and really only used what was commented on in the php script itself..however:

function cleanUpTempFolder();

doesnt seem to be working for me....or.. maybe Im not understanding it correctly?

anyone around here anymore.. :)

thanks

Posted by: xl97 on July 26, 2008 07:58 AM

Hi Guy's,

Can someone explain to me why in pallette mode there is the check for

if (offset 0x7fff)
{
}

What des this so? what is 0x7fff and what does offset refer to?

Thanks
slinky2000

Posted by: slinky2000 on July 28, 2008 06:30 PM

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.

Posted by: Mario Klingemann on July 28, 2008 07:08 PM

Hi Mario,

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.

Any tips would be gratefully received.

Cheers
Steve

Posted by: Steve on August 3, 2008 11:39 AM

Okay, found the issue (should've checked harder before posting!). Apparently MTASC doesn't like the EventDispatcher if you compile with the -mx flag in the compile string.

Posted by: Steve on August 3, 2008 11:53 AM

The app is great, I've been looking for this for a long time now.

My problem is, when I test locally within flash using ctrl+enter, it works. But anywhere else, I get this error :

ERROR: [onImageHandle] HTTP Error null

Thanks in advance!

Posted by: Nicolas on August 6, 2008 10:24 PM

Mario-

can you help out with the PHP auto deletion of files/images after 1 day old? (or whatever the default is?) this has never worked.. and am looking for some help/advice?

Does it have to be enabled somehow? another parameter then turns this on or something?

or ANYBODY!? Has anybody gotten this to work?

PLEASE..

thanks

Posted by: xl97 on August 11, 2008 05:49 PM

geez- with all the SPAM BOTS.. can anyone even see my cry for help? LOL

anyone got the PHP script to auto check for any images older than 1 day?? ANYONE? at least reply back NO..so I don't beat a dead horse here. :)

thanks

Posted by: xl97 on August 19, 2008 07:54 PM

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?

your post has really not offered anything useful...
(of course)

Posted by: xl97 on August 20, 2008 10:56 PM

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.

Posted by: Kingoman on September 15, 2008 12:23 PM

Hi,

Im building a drag & drop game, which is a Movie clip. What Id 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. Im running Flash 8.

Any help Id be greatly appreciated.

Posted by: kay on October 4, 2008 06:01 PM

Hate to be one more person begging for answers on here, but i think that this is a pretty easy one (i'm just still a n00b at this):

what does it mean if i never get past "sending (0%)" status?

Posted by: jm on October 6, 2008 07:07 PM

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.

Posted by: Mario Klingemann on October 6, 2008 07:28 PM

hey mario, excellent work. impressed how easy you made it to implement and customize.

my problem now is that i'm trying to get multiple movie clips (from the same file) to save to the same jpg. i'm probably missing something obvious, but i've searched everywhere and no luck.

thanks

Posted by: avery on October 7, 2008 03:29 AM

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.

As for the right matrix you should use - this post might give you somewhat of an idea: http://www.quasimondo.com/archives/000670.php

Posted by: Mario Klingemann on October 7, 2008 11:30 AM

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.

Any help from anyone would be greatly appreciated!

Posted by: jm on October 7, 2008 07:50 PM

Hi,
Thanks very much for the great code.

I have one question, Please.
I want to make a .png of the stage using,

snapshot.draw(this);

How could I also set the x and y coordinates for the snapshot?

Thanks very much for any help you can provide.

Posted by: mateo on October 8, 2008 04:27 AM

mateo: check the link I just posted 2 comments above.

Posted by: Mario Klingemann on October 8, 2008 11:08 AM

Hi!

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.

Did you ever have similar problems with users?

Thank you!

Best regards

Janine

Posted by: Janine on October 13, 2008 10:09 AM

Sounds like you've hit some posting size limit. I haven't heard of that problem with BitmapExporter, but since I send data in multiple packets it's unlikely that this will happen.

Posted by: Mario Klingemann on October 13, 2008 10:39 AM

hi mario,

if i set the dontRetrieve to true, how do i listen for the saved event?

any sample code?

Posted by: chup on October 14, 2008 06:07 AM

hi mario,

i sorta mange to figure out how to call the listener, here my code

--------
this.saved = function() {
onSaved(this);
};

function onSaved(eventObj:Object) {
trace(eventObj.url);
trace(eventObj.fileName);
trace(eventObj.uniqueID);
trace(eventObj.sentBytes);
trace(eventObj.time);
trace(eventObj.compressionRatio);
}
-------

but the onSaved function won't work, did i do it wrongly?

Posted by: chup on October 14, 2008 08:00 AM

In that case you listen to the "complete" event.

Not sure what you are doing with the this.saved ... stuff. Compared tos the AS3 way of event listening the way BitmapExporter does it is admittedly "old school", but this is how it usually works:

BitmapExporter.addListener("complete", this );

function complete(eventObj:Object) {
trace(eventObj.filename);
trace(eventObj.sentBytes);
trace(eventObj.time);
trace(eventObj.compressionRatio);
}

Posted by: Mario Klingemann on October 14, 2008 12:22 PM

hi mario,

thanks for the reply :)

i try your code

BitmapExporter.addListener("complete", this );

function complete(eventObj:Object) {
trace(eventObj.filename);
trace(eventObj.sentBytes);
trace(eventObj.time);
trace(eventObj.compressionRatio);
}

but it return me an error
>> there is no method with the name 'addListener'

any idea why?

Posted by: chup on October 14, 2008 12:46 PM

Sorry - it's of course addEventListener

Posted by: Mario Klingemann on October 14, 2008 01:35 PM

hey mario

here my code, but it trace nothing... weird

BitmapExporter.addEventListener("progress",this);
BitmapExporter.addEventListener("status",this);
BitmapExporter.addEventListener("error",this);
BitmapExporter.addEventListener("complete",this);
BitmapExporter.addEventListener("saved",this);

function complete(eventObj:Object) {
trace("hello word")
trace(eventObj.filename);
trace(eventObj.sentBytes);
trace(eventObj.time);
trace(eventObj.compressionRatio);
}

Posted by: chup on October 14, 2008 02:20 PM

hey mario,

this work pretty fine for me, so i'm going to stick to the "saved" listener :)


---------------

BitmapExporter.addEventListener("saved",this);

function saved(eventObj:Object) {
trace(eventObj.filename);
trace(eventObj.sentBytes);
trace(eventObj.time);
trace(eventObj.compressionRatio);

}

Posted by: chup on October 15, 2008 03:12 AM

cool work thanks bookmark you boob tube =)
hq tube

Posted by: xtube on October 20, 2008 02:02 AM

greaaat site dude very thanks zootube =)
xvideos

Posted by: boobtube on October 20, 2008 02:03 AM

wef kgjhkfld;lkgg mf,lc bng dnbdsgdsk dnjf m x tube =)
zoo tube

Posted by: redtube on October 20, 2008 10:06 AM

Welcom,

I used BitmapExportet in my project - it creates a picture JPG (2057 px x 2880 px).

I noticed that in the output file some lines are shifted in the right side. So the object which is right bottom align comes from the left side.

I have a problem to explain it - see the example.

Example: http://img48.imageshack.us/my.php?image=251xk7.jpg

Thanks for any help

Posted by: Bart on October 24, 2008 04:33 PM

This looks like a bug in the encoder algorithm. Which one do you use? Can you please try to use a different one and check if the same error occurs?

Posted by: Mario Klingemann on October 24, 2008 04:43 PM

Hello Mario,

I used "palette" mode.
Now I tried with "default" and it looks OK

Check: http://img356.imageshack.us/my.php?image=1cc34b464941fa998d35bfahy1.jpg

I'm wondering what can be wrong.

Best regards.

Posted by: Bart on October 24, 2008 10:07 PM

I've downloaded your php file and uploaded to my server unedited and i still get this error
ERROR: [onImageHandle] ".urlencode($message) );

}


?>

do you know what could be causing this error.

Thanks,

zo

Posted by: Alfonzo on October 28, 2008 08:00 PM

I'm a flash guy not php. Do I need to have something else installed on the server for this php file to work for me?

Thanks,

zo

Posted by: Alfonzo on October 28, 2008 09:36 PM

Your error message looks rather strange as if the php is not properly executed. What happens if you open the the bitmapexporter.php on your server right in the browser?

Posted by: Mario Klingemann on October 28, 2008 09:50 PM

I figured it out. I was trying to run the script from a sub Domain and I had to put it in the root.

zo

Posted by: Alfonzo on October 28, 2008 10:41 PM

Hello,

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.

Sincelery,
-Timo Palokankare
Advertising Agency SST

Posted by: Timo Palokankare on November 3, 2008 11:27 AM

Hi Timo,

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.

Posted by: Mario Klingemann on November 3, 2008 12:39 PM

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.

Posted by: Rafael on November 5, 2008 02:48 AM

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

Posted by: Mario Klingemann on November 5, 2008 11:11 AM

Mario, great job with this.

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.

Posted by: Matt on November 7, 2008 06:33 PM

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.

Posted by: Mario Klingemann on November 7, 2008 07:42 PM

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.

Posted by: Mario Klingemann on November 10, 2008 07:45 PM

doh...you are right:

function saved(evt:Object):Void {
trace("SAVED FUNCTION TRIGGERED");
trace("EVENT URL :"+evt.url);
}

works perfectly..


THANKS (maybe one of these days I'll get my project done) appreciate the feed back. =)

Posted by: xl97 on November 10, 2008 09:05 PM

Changing the JPG header to 012C changes the JPG DPI to 300dpi, but does anyone know how to change it to say, 300.12 DPI?

Posted by: Adam on November 11, 2008 06:56 AM

i have adapted $DOWNLOADURL in the php file to use PHP_SELF.

$DOWNLOADURL = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?mode=download&name=";

algo i have discovered that if i try to set $RELATIVE_SAVEPATH to a directory which is one level up from the php i get an IO Error from the FileReference object in flash.

i tried putting:
$RELATIVE_SAVEPATH = "../BitmapExporter_Tempfiles/";

my directory structure looked like this:

/BitmapExporter_Tempfiles/
/PHP/BitmapExporter.php

i had to put the temp folder in the same location as the php

Posted by: jonito on November 11, 2008 04:35 PM

Hi,
first of all, thanks for this script! .. however my problem is that, snapshot manager is stucked on "Initializing" when i run it inside the browser. But works fine inside flash IDE ...


What do u think missed? Thank you sir.

Posted by: Joel on November 26, 2008 06:09 AM

hi Sir,

I'm having this error when i run the script in html ERROR: [onImageHandle] HTTP Error .. but it's working ok when i run the script inside flash IDE ...

What do you think is the cause of this?

Thanks much.

Posted by: Joel on November 27, 2008 10:25 AM

I have the same problem like as Joel. What can we do?

Thanks for your great application.

Posted by: Carlos on December 1, 2008 02:35 PM

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.

Posted by: Mike on December 2, 2008 10:31 PM

Thanks for this source very much!

It is work before but when after using flasplayer10 is some error .

ERROR: [onSave] Dialog box failed to open.

pls help for this error !

thx

Posted by: Stanley on December 3, 2008 06:54 AM

Flash Player 10 FileReference Changes:
http://theflashblog.com/?p=423

Posted by: guest on December 4, 2008 05:15 AM

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.

Posted by: syawal on December 4, 2008 10:09 AM

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.

Posted by: Mario Klingemann on December 5, 2008 06:58 PM

hello Mario

I have a problem download the image.. below is my log file

mode: getImageHandle
mode: default
appendToTempFile: 997c2fe38971c0e3e524e933131582c1 272199 Bytes
mode: default
appendToTempFile: 997c2fe38971c0e3e524e933131582c1 285204 Bytes
mode: default
appendToTempFile: 997c2fe38971c0e3e524e933131582c1 357036 Bytes
mode: default
appendToTempFile: 997c2fe38971c0e3e524e933131582c1 393810 Bytes
mode: default
appendToTempFile: 997c2fe38971c0e3e524e933131582c1 269952 Bytes
mode: default
appendToTempFile: 997c2fe38971c0e3e524e933131582c1 154029 Bytes
mode: save
File BitmapExporter_Tempfiles/997c2fe38971c0e3e524e933131582c1.jpg (55815 Bytes) created
mode: download
mode: dropImageHandle


the program popup the save dialog box.. but the file looks like corrupted.. everytime when i try to download... the downloaded file size only 70byte..

any idea what it caused?

Posted by: dexidle on December 12, 2008 07:14 AM

I already solved the problem... its regards to Flash player 10 issue.. its prevent open/save dialog box to open without user action (onRelease button or etc).

Posted by: dexidle on December 13, 2008 12:02 AM

dexidle, how did you fix the "Dialog box failed to open" problem?

Posted by: mike on December 13, 2008 05:17 PM

I am w/ Mike- any fixes for the dialog box not opening from fileref change??

_A

Posted by: Asimo on December 16, 2008 06:58 PM

here is the trick

http://www.dayaone.com.my/BitmapExporter/bitmap-exporter-flashplayer10.html

Posted by: dexidle on December 17, 2008 03:18 AM

Hi

tx for ur code but i want to know how to make png export to 300 dpi.. currently it shows 72 dpi only

Posted by: Nishit on December 19, 2008 08:18 AM

HTTP Error null
- I finally found out the cause of this error....

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 ....


Hope this helps ....

Posted by: Joel on January 2, 2009 09:52 AM

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..

Rgrds
Kannan.B

Posted by: kannan on January 12, 2009 11:29 AM

anyone know why I keep getting this error. even in the example above?

" ERROR: [onSave] Dialog box failed to open."

Posted by: on January 25, 2009 08:59 PM

Anyone got some tips on where to start debugging for this type of error:

Message: Waiting for Server...
Current %: 0.95
Total %: 1
Message: Waiting for Server...
Current %: 0.95
Total %: 1
Message: Waiting for Server...
Error opening URL "http://www.mydomain.com/directory/subdirectory/BitmapExporter.php"
HTTP error 406
ERROR: HTTP error 406
STATUS CHECK1: idle
[onAddPixelBlock] HTTP error null
ERROR: [onAddPixelBlock] HTTP error null
STATUS CHECK1: idle

I cant seem to move forward on this AT ALL..

thanks

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

to give ore details:
Error opening URL "http://www.mydomain.com/directory/subdirectory/BitmapExporter.php"

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..

if I upload a picture of a persona face.. it fails..


Current %: 0.95
Total %: 1
Message: Waiting for Server...
Error opening URL "http://www.somedomain.com/directory/subDirectory/BitmapExporter.php"
HTTP error 406
ERROR: HTTP error 406
STATUS CHECK TRACE: idle
[onAddPixelBlock] HTTP error null
ERROR: [onAddPixelBlock] HTTP error null


I have tried fastscan, turboscan, default and RGB settings.. "ALL" do the same thing.. different compressions as well...

tried saving and both .jpg & .png too..

example:
BitmapExporter.saveBitmap(snapshot, "exportImage.png", "rgb_rle", 0, 100, true);

BitmapExporter.saveBitmap(snapshot, "exportImage.jpg", "default", 0, 60, true);

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.

Posted by: Mario Klingemann on February 10, 2009 09:45 PM

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)

BitmapExporter.saveBitmap(snapshot, "somePic.bmp", "rgb_rle", 0, 100, true);

Thanks for keeping up with 'us' here Mario.. appreciate it. =)

Posted by: xl97 on February 11, 2009 09:36 PM

Sorry, (me again)..
Im at: PHP Configuration for my domain..

Safe mode is: OFF
max_execution_time: 30
max_input_time: 60
memory_limit: 32M
register_globals: OFF (Im hard coding paths anyways)
upload_max_filesize: 2M
zend_optimizer.version: 3.3.3

Im not sure where to check from here? or what to ask/get changed on my domain/php configuration to help this error.

Thanks

Posted by: on February 11, 2009 10:42 PM

I found the be_log file (finally), not sure if this will help any.. I havent seen any PHP error logs

but this is what the be_log file says: (sample of it, but all the same)


mode: dropImageHandle
mode: getImageHandle
mode: dropImageHandle

cant even post it, because Im getting a 'questionable' content' error/warning or something..

Posted by: xl97 on February 12, 2009 12:27 AM

How about emailing me the log file? mario [at] quasimondo.com

Posted by: Mario Klingemann on February 12, 2009 09:38 AM

sent..


seems to just be doing this over & over..
mode: getImageHandle
mode: dropImageHandle
mode: getImageHandle
mode: dropImageHandle


I deleted be_log.. cleared out directory.. tried two more times..and that was the results?

not sure 'what' is causing this..or 'how' to fix it?

but i read people were creating 300 DPI images.. so I doubt its a file size thing...

thanks...

Posted by: xl97 on February 12, 2009 05:14 PM

Hi Mario,

Thanks for the source code....its awesome! I am basically modifying this code to just grab the image and save it on the server side.

I have already made most of the changes related to path and file name but I still encounter an error

ERROR: [onImageHandle] HTTP Error null

Though the app works perfect when I 'Test Movie' in Flash.

But whn I upload it on a server in an html file it gives me this error.

Really appreciate if you could help me out....thanks!

Posted by: Ankit on February 28, 2009 07:44 PM

Hello to all ! Greetings From Poland. very Good Page !

Posted by: greetingsfrompoland on March 7, 2009 04:51 AM

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!!

Thanks again,

Claire

Posted by: Claire on April 9, 2009 01:29 PM

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.

Posted by: Mario Klingemann on April 9, 2009 09:15 PM

Hi Mario,

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! :)

Claire

Posted by: Claire on April 11, 2009 02:29 PM

Hello,
Great, great script. I would purchase in a heartbeat, however, one question:

Is it possible to use this script in conjunction with a form box to send the image via email to the entered address? Sorry if this was already asked, I don't have a lot of time to investigate.

Posted by: Ben on April 14, 2009 07:44 AM

Hi Mario,

I have one more question, much the same as Ben's above. I have used the code:

function saved( e:Object ){

trace("image URL: "+e.url);
trace("image filename: "+e.fileName); trace("image uniqueID: "+e.uniqueID); trace("sentBytes: "+e.sentBytes); trace("time: "+e.time);
trace("compressionRatio: "+e.compressionRatio);
}

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?

Any help is greatly appreciated, thanks for answering my questions!

Kind Regards,

Claire

Posted by: Claire on April 15, 2009 05:21 PM

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.

Posted by: Mario Klingemann on April 15, 2009 05:34 PM

Is there any script can upload the images automatically to the server ?
please..

thanks

Posted by: abe on April 16, 2009 08:28 AM

Thanks for the help Mario! That's great! The only problem is, I have put everything online and now it wont work, this error comes up:

ERROR: [onAddPixelBlock] WARNING [2] fopen(BitmapExporter_Tempfiles/f7795a679a8ae5476cb0881adda5f562.tmp) [function.fopen]: failed to open stream: Permission denied

Do you know what this means?

Thanks!

Posted by: Claire on April 21, 2009 04:26 PM

It looks like you have not set the folder permissions correctly on your server. If you search this page for "Permission denied" you will find mored detailed answers to this question with links.

Posted by: Mario Klingemann on April 21, 2009 04:51 PM

thanks mario, got it working!! i promise not to bother you again!! thanks so much for the help!! :)

Posted by: Claire on April 21, 2009 07:03 PM

Mario,

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?

Thanks for your time.

Posted by: JHight on May 22, 2009 11:07 PM

hi mario,

thank you for this wonderful class. does the class have problems with php5?

wie tested our application on different servers and it just works on one server with php 4.4

all other are > 5.2

on this server we just get a white png. in the tmp file there are just

and the log-file says:
48.png (48955 Bytes) created

thank you for help
xac

Posted by: xac on June 17, 2009 12:37 PM

hi mario, its me again. sorry.

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...

has anyone a tipp or solved this problem?

thanx xac

Posted by: xac on June 18, 2009 08:25 PM

.... hm, it seems to be a problem with the security ....
it works with www. and not without ...

Posted by: xac on June 18, 2009 11:56 PM

Hi Mario,
its really great,thanks a lot.
thanks

Posted by: hasib on July 3, 2009 10:23 AM

Hi Mario,

Nice stuff. Thank you because willing to share. :)

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.

Posted by: Sharini on July 6, 2009 06:54 AM

Sorry... huh.. i didnt notice the php folder was inside the file.. my mistake.. :)

Posted by: Sharini on July 6, 2009 09:09 AM

Hola a todos, no hablo mucho ingles asi que espero que alguno sepa Espaol este es mi problema:

How rename the file that generate for "BitmapExporter.php ", becouse generate a file for examble: "76aef8453fdc9d9661b842049650e884.jpg" remplace for " image.jpg "??

How remplace name ?

Posted by: Larc on July 16, 2009 10:00 PM

ERROR: [onSave] Dialog box failed to open.

Posted by: on September 11, 2009 01:13 AM

Hola
What to do in that case?

thank you

Posted by: trumoc on September 11, 2009 01:16 AM

This is due to new security restrictions of the Flash player. You cannot download a file without a mouse click. Please read my answers further above how to work around this.

Posted by: Mario Klingemann on September 11, 2009 11:02 AM

This is probably ancient history, but after failing to get any PHP solutions to run (my cheap hoste dosn't seem to support this), I found it was possible, and easier to save direct to disk in F10.
http://ntt.cc/2009/01/09/as3corelib-tutorialhow-to-use-jpegencoder-and-pngencoder-class-in-flex.html

Posted by: Peter Strmberg on September 28, 2009 03:58 PM

Hi Mario,

Thanks a lot for your awesome work here.

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.

Any ideas how or why the exporter never returns to "idle" state?

Thanks again for your help.

Posted by: Josh on October 13, 2009 04:37 AM

Hi Mario,

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.

Any help would be very appreciated.

Thanks!

Posted by: Josh on October 14, 2009 06:56 PM

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?

Posted by: Mario Klingemann on October 14, 2009 07:13 PM

Thanks for getting back to me Mario.

Yes I'm using the reset() function, which successfully sets the status to idle.

After that, the error comes up.

Any ideas?

Posted by: Josh on October 14, 2009 07:31 PM

Some more details of the issue:

specifically my code to reset the status is this:
BitmapExporter.resetStatus();

The error that comes up is this:
ERROR: [onAddPixelBlock] Unknown Command: undefined

Thanks,
Josh

Posted by: Josh on October 14, 2009 08:06 PM

hi mario,

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.


first, add the following code to your FLA:


function launchSaveAsDialogue()
{
var my_lv:LoadVars = new LoadVars();
my_lv.wallpaper = this.wallpaper;
my_lv.send("_server_file_folder/_popup.php","_self","POST");
};


function saved()
{
wallpaper = BitmapExporter["uniqueID"];

// 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.

// MSIE 7
if (strstr($HTTP_USER_AGENT,"MSIE"))
{
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-type: image/png");

$wallpaper = $_POST['wallpaper'].".png"; // get filename from Flash

//$wallpaper = "wallpaper_1261618541.png"; // use a known file in (same folder as PHP) to test "save as" pop-up dialog

header("Content-Disposition: attachment; filename={$wallpaper}");
header("Content-Transfer-Encoding: binary");
}
else // below OK with FF and Opera
{
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Pragma: no-cache"); // comment this line out in https
header("Content-type:image/png");

$wallpaper = ($_POST['wallpaper']).".png"; // get filename from Flash

header("Content-Disposition: attachment; filename=".$wallpaper);
}

readfile($wallpaper);

clearstatcache();

?>

cheers!


Posted by: mark on December 31, 2009 01:04 AM

Hi Mario!

Cooles Script! Ich htte eine Frage zum Einbinden von Graphiken in den abzuspeichernden Bereich.

Ich speichere meinen Stage ab mittels:

var image_mc:MovieClip = new MovieClip()
var snapshot:BitmapData = new BitmapData(x,y,false);
...
...funkt soweit

wenn ich aber einen zustzlichen Clip einbinde, z.B.:

this.createEmptyMovieClip("logo_mc", 998);
loadMovie("http://www.google.com/images/logo.gif", logo_mc);

dann sehe ich den neuen Clip zwar am Stage , das abgespeicherte Bild ist aber leer. Was mache ich falsch?

Danke fr Deine Hilfe. Lg, Michael

Posted by: Michael on February 3, 2010 11:12 AM

Das Problem in dem Fall ist die Flash Security Sandbox. Man kann Bilder, die von einer anderen Domain geladen wurden nicht ohne weiteres in eine Bitmap bertragen. Um das zu ermglichen mu auf dem anderen Server eine crossdomain.xml Datei angelegt sein, die diesen Zugrif explizit erlaubt.

Hier ist ein Artikel zu dem Thema:
http://www.quasimondo.com/archives/000650.php

Falls der andere Server keine crossdomain.xml anbietet, kann man die Bilder nur ber einen proxy auf dem eigenen Server laden. Dazu hatte ich auch mal was verffentlicht:
http://www.quasimondo.com/archives/000407.php

Posted by: Mario Klingemann on February 3, 2010 11:49 AM

Danke fr die rasche Antwort. Hab das Image lokal am Server verfgbar gemacht und jetzt wird es "eingebunden" und ist am Snapshot sichtbar. Danke fr den Tipp!!!

Leider enthlt das RAR File swfimageproxy_v04.rar keinen Code sondern nur zwei PHP files und ein SWF.

Posted by: Michael on February 3, 2010 12:25 PM

Das hat schon seine Richtigkeit mit dem RAR File - ein proxy kann immer nur serverseitig arbeiten, daher gibt es da auch keinen Actionscript zu.

Posted by: Mario Klingemann on February 3, 2010 12:45 PM

Naja, der Code vom "demo.swf" (demo.fla?) der im Beispiel verwendet wird, wrde mir schon sehr helfen. :)

Posted by: Michael on February 3, 2010 01:50 PM

Da gibt's es aber nicht wirklich code - alles was man macht ist es anstelle das Bild direkt zu laden sie ber den proxy aufzurufen, also http://www.deinserver.de/swfimgproxy.php?url=http://www.google.com/images/logo.gif

Posted by: Mario Klingemann on February 3, 2010 02:07 PM

Ok, sorry fr Deine Mhen. Ich bin leider kein Programmierer. :( Jetzt ist es klarer. Vielen Dank!!!

Posted by: Michael on February 3, 2010 02:29 PM

It FAILS, says "ERROR: [onSave] Dialog box failed to open." when I try the demo

Posted by: jep on February 5, 2010 03:32 PM

If you have a look at the previous comments you will learn that this is due to changed security behaviour of the flash player.

Posted by: Mario Klingemann on February 5, 2010 03:48 PM

Thank you very much Mario.This is perfect tool!
Can i control the resolution of the output image or its just 72 dpi?
thanks in advance

ruDzt loGan

Posted by: ruDzt on May 13, 2010 12:21 PM

The output resolution is fixed. It seems to be possible to override the dpi info in a jpeg but I don't think that i'll add that to the code.

BTW - here is an excellent summary about dpi and bitmaps in general: http://www.unleash.com/knpepper/dpi/

Posted by: Mario Klingemann on May 13, 2010 12:27 PM

How do you solve this problem?
ERROR: [onSave] Dialog box failed to open.

NOTE: Before anyone jumps on me. I DID SEARCH and all I can find is people saying to "DO A SEARCH".

Posted by: damned on August 2, 2010 11:31 PM

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

Posted by: Mario Klingemann on August 3, 2010 10:51 AM

Just wondering if you could tell me how to pass the uniqueID var back to the flash?

Posted by: george on August 10, 2010 05:46 PM

Never mind. I found out by reading previous posts. Thanks.

Posted by: George on August 10, 2010 05:55 PM
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?



Thank you!

Most Visited Entries
Sketches, Works & Source Code
Lectures
Contact
Backlog
In Love with
Powered by
Movable Type 2.661

© Copyright Mario Klingemann

Syndicate this site:
RSS 1.0 - RSS 2.0

Quasimondo @ flickr
Quasimondo @ LinkedIn
Quasimondo @ Twitter
Quasimondo @ Facebook
Quasimondo @ MySpace
Quasimondo is a Bright
Citizen of the TRansnational Republic
My other blog in german
Impressum


My family name is written Klingemann,
not Klingelmann, Klingeman, Klingaman, Kingemann,
Kindermann, Killingaman, Klingman, Klingmann, Klingonman
Klingemman, Cleangerman, Klingerman or Kleangerman

profile for Quasimondo at Stack Overflow, Q&A for professional and enthusiast programmers