Even if this article might seem to be a bit anachronistic - believe it or not - there are many people out there who still have to code in Actionscript 2.0 and who publish for Flash Player 8. And it looks like there are more and more projects where there is a requirement to save users' drawings, compositions or webcam snapshots to a server in order to add them to galleries, mail them to friends or simply download them.
Since the number of inquiries for commercial licenses of my BitmapExporter class has increased considerably I've decided to revise the code once more. The new version has been optimized in several places so the overall performance should be remarkably better. It also turned out that some encoding optimizations that I had used seemed to create compatibility issues with Asian operating systems. (Patrick - I should have listened to you earlier ;-) ...)
Here is a demo that allows you to play with different image types and the various settings that BitmapExporter offers:
The main features of BitmapExporter are:
- send any BitmapData object to a PHP server-side script with one line of code (currently alpha channels are ignored for performance reasons)
- if you only need PNG or BMP files a plain PHP installation is sufficient
- for JPEG support you will need a PHP installation with GD compiled in - this usually comes with the default package anyway
- option to automatically popup a download window for the user after the upload has been completed
- choice of 5 different encoding options depending on image content and size and desired encoding time / data size ratio
- highly optimized data encoding for maximum save speed
- automatic data chunking in order to avoid Flash timeout warning with big images (except for turboscan mode)
- adjustable time slice for background saving in order to play nicely with the application and not to hog resources
BitmapExporter can theoretically save bitmaps up to Flash's maximum allowed size of 2880x2880 though it will take quite some time to save huge bitmaps like this. If you are planning to work with these sizes I recommend you to go for an AS3 solution since Flash 9 has much easier and faster possibilities to save Bitmaps.
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 readingHi 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 PMThis 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 !!
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
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 PMJohn: 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 PMMario,
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
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 PMHi Mario I was wondering if you would be able to help me with a problem. I have been searching for a way to retrieve a 300 dpi image instead of the standard 72 from a swf. Any suggestions or direction would be greatly appreciated.
Thanks,
Adam
Adam: From reading through the PNG format specifications I think that there is an option to add the resolution information to the file. For the moment I can only add that feature to the wishlist. I recommend you to run the created images through a batch script or a Photoshop action to change that info. I guess you are aware of the fact that the resolution info which comes with the image does not change the absolute number of pixels.
Posted by: Mario Klingemann on May 30, 2007 11:15 AMAdam, 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.
That's an excellent find, Mike! Thanks for sharing this.
Posted by: Mario Klingemann on May 30, 2007 03:37 PMMike - 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 PMI 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 PMThe necessary code in php btw:
$handle = fopen($myJpg, "r+");
fseek($handle, 13);
$dpiData="\x01\x01\x2C\x01\x2C";
fwrite ($handle, $dpiData);
fclose($handle);
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 PMI'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 PMWhen i was looking for a way to save JPEG images in AS3 it took a long time to find out that adobe had AS3 classes for saving JPEGs and PNGs. I just wanted to mention that if you are using AS3 you don't need to go to any trouble to save JPEG images.
Here is a link to get you started with Adobe's utility classes.
P.S. Why not just convert the AS3 classes to AS 2 and use this clean approach to doing the conversion in the flash player?
Andrew: I'm well aware (and even mention it in the post above) that with AS3 there is a whole bunch of faster and better solutions available to save bitmaps.
There are at least two reasons why these solutions will not work in AS2:
- performance: AS3 is up to ten times faster when it comes to operations like looping through an array or converting strings.
- handling of binary data: Flash 8 cannot work with binary strings, or rather it cannot handle the chr(0) character because that is used as the marker for end-of-string. That is why in Flash 8 all these workarounds are necessary to work around this. Flash 9 has got the new ByteArray which even comes with a native compress() method.
Here is that link again.
http://blog.andrewpaulsimmons.com/2007/05/save-jpeg-or-png-in-actionscript-30.html#links
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 AMHi: This is great stuff. One issue I am getting, It is working great on my local machine, but I install it on the website, it is not displaying anything. I mean saving the output. I checked all the stuff requires are available on the server. Please help me.
Mike Duguld, your bussiness card demo uses AS2 or AS3? I saw it saves the JPG incredibly fast... what class are you using? I use this class and it's terribly slow for a jpg 500x375 (almost an entire minute to save it). I hope I can approach that speed someway
Thanks
Savador: the business card demo is so fast because it doesn't send the image as a bitmap at all but it just sends the infos like texts, template type, alignment etc to the server where the actual bitmap gets constructed from prepared elements.
Posted by: Mario Klingemann on June 3, 2007 01:11 PMHi. Thanks for this great class. I just have one problem: when I click "save", he creates the new image on the folder "BitmapExporter_Tempfiles", and opens the window to browse. Then and choose the destination folder and click "save", but no image is saved in my computer.
Then I removed the code
+ ( deleteAfterDownload ? "&delete=1" : "" )
from BitmapExporter.as and this way it works fine, I can save the picture in my computer, but obviously, the image created on "BitmapExporter_Tempfiles" is not deleted after download.
Can you please tell me what I did wrong in the first case?
Thanks
António: I'm not sure what the exact issue is, but it looks like on some servers the file gets deleted before it actually has been completely sent - which is strange since in the php sourcecode the two commands come after each other. But you don't have to change the BitmapExporter sourcecode in order switch off the autodelete feature - just use the expression BitmapExporter.deleteAfterDownload = false;
BitmapExporter will automatically delete all images and temp files from the temp folder that are older than one day.
Posted by: Mario Klingemann on June 4, 2007 05:57 PMHi Jim. Photos i received. Thanks
Posted by: Bill Compton on June 5, 2007 12:28 AMHey 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 PMIs 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 PMvery nice, you need to update to AS3, and see real power.
but so so work.
Ok, take care Quasimodo from Notre Damme.
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 AMHow 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 PMThis is great, i been looking for this for months
Thanx
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 PMI 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 PMActually 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 PMHave 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 PMKevin: 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 AMJay - 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 AMI've got the same prob as june 4th. Everything works smooth and fast, the image is created on the server, the save dialog box comes up, I click ok, but the image is not saved. I've set BitmapExporter.deleteAfterDownload = false;
in the fla and the .as. Any ideas?
Mario - I would like to purchase a License. Could you send payment details to me?
brett (AT) neo-pangea (DOT) com
Thanks!
Brett
@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();
@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 PMMario : 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 PMI 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 PMalan: Did you already try to change the whole line to
$DOWNLOADURL = "http://www.3wme.com/tests/BitmapExporter.php?mode=download&name=";
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 AMMario -
"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 PMWhow... 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 AMYou 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 PMHey 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
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 PMHey 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
With save mode I mean the compression method - e.g. "fastscan", "default" or "palette"
Posted by: Mario Klingemann on July 18, 2007 12:40 PMIt 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.
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 AMHey 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 PMHey Mario,
Can i control the resolution of the output image or its just 72 dpi or the default screen resolution.
thanks in advance
Alok
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 AMWhat 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 AMThe 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 AMI'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 AMDid 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 AMThanks 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
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 PMLooking 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 PMThe new version works perfectly without commenting out anything. Great work!
Posted by: tod on July 26, 2007 03:53 PMIn 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 AMYou 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 PMI 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 PMTo 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 PMMario, 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 PMJorge: 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 PMIs 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 AMYou 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 AMhi,
where put true for the argument dontRetrieve? in the bitmapexporter.as
thanks..
Posted by: carolina on August 7, 2007 08:09 AMIt 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 AMI 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 PMYes, 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 PMHi Mario,
Do you have any idea how can I show an image in a browser without saving it on the server?
thanks in advance
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 PMThe image is generated by user, comes from Flash in ByteArray and is saved on PHP-side with file_put_contents, after downloading or showing in browser it is deleted. This works.
The problem is that I dont have write access on the server, so I can't create a temp-folder to put the file there and then delete it. I like to show the image in browser directly or download it but without saving it on the server.
Okay I understand. If you cannot store anything permanently on the server I guess you could at least store some data in a session variable. This might enable you to access the image data over multiple requests. Of course this will still limit the access to the one user who created the image.
Posted by: Mario Klingemann on August 9, 2007 01:04 PMMario, 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 PMJorge:
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 PMFor 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 PMhi 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 PMOh, 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.
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.
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);
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 PMBoth 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 PMWhat 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 PMYou 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 PMHi,
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 PMThat'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.
Hi,
I get again another message [onAddPixelBlock] HTTP error 0 ERROR: [onAddPixelBlock] HTTP error 0
Posted by: Martin on August 23, 2007 04:03 AMDoes 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 AMHey 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 PMHi 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.
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 ;-)
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 AMIsn'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 PMHello 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 ??
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 PMThank 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
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 PMThank you Mario
for replying and giving me a direction.
Thanks again. :)
Inder
Is there anyway to output AS 2.0 images to 300 dpi without GD?
thank you,
Emma
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 PMHi 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 AMHi 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 PMand here is the other error message
ERROR: IO error with file snapshot.png
I get the same error as JJ
"IO error with file snapshot.jpg"
Any help?
Posted by: andrew on September 18, 2007 08:19 AMAs 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 AMAnd 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)
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 PMHoi 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 PMForgot to say, I'm trying to export jpg
Posted by: Bauke on September 20, 2007 04:06 PMAnd 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 PMHey 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 PMRiddle 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 PMTraced 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 PMcan 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 PMhello,
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 PMMy 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 PMSounds 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 )
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 PMHi, 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 PMSince 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 AMHi, 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 PMFor 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 PMA 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 PMHI, 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 AMhey mario, i'm getting "ERROR: [onSave] undefined"
what causes this error?
Posted by: matt on October 11, 2007 02:03 AMhey 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
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 AMMatt - 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 AMHi, 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 PMSorry 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 PMSorry, 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 PMwhat php libraries does this require?
Posted by: matt on October 11, 2007 07:51 PMmatt: 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 PMI 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 PMi 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
do you have a suggestion regarding how much memeory the php should be alloted?
Posted by: matt on October 12, 2007 07:13 PMHi,
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
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 PMher 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 PMOh 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 PMhey 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 PMYou 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 PMsorry 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 PMBitmapData.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 PMgot it, thanks for your time mario
Posted by: q on October 23, 2007 11:26 PMHi 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 PMHi 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
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 PMTHanks 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
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 AMOh, 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 AMInternet providers release information about their users at the first official request. Your ISP, your boss, or someone can be monitoring all your internet activities at this very moment.
Some users might want to enjoy more privacy than that.
That is why you should use the internet-anonymity service.
Hey Mario - First off, amazing work here. I'm blown away when I see my 300x300px vector image save in less than 5 seconds. (using palette mode) You've made this extremely easy to use man. Anyone who has ANY problems whatsoever, does not know much. hehe.
So thanks a lot and you will hear from me soon about compensation for a commercial project. :)
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 PMThe 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 PMJust 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 PMHi 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
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 PMthanks 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
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 );
}
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 PMHey 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 PMok 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 PMHi 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 AMBitmapExporter 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 PMThanks 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 AMHi,
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??
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 AMThis 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...
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.
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!
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..
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 PMMario 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 PMdear 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
mario
in addition to my previous post - when i copy the script to my application i get
"error"...line 177 classes may only be defined in external actionscript 2/0 class scripts"
what does it mean?
ehud
Sorry but I cannot give you an introduction to Actionscript 2.0 here - please press the F1 key inside your Flash Application and read the really good tutorials there. There is even a search option so if you search for "classes" you should find plenty of starting points.
Only so much: you do not paste the code which is contained in BitmapExporter.as into your fla, but you have to copy the folder structure and the as into the same folder in which your fla resides. You can also manually create those folders:
- Go into the folder in which your FLA sits
- create a folder called "com" if it does not exist yet
- go into the "com" folder
- create a folder called "quasimondo"
- go into the "quasimondo" folder
- create a folder called "display"
- go into the "display" folder
- copy the file "BitmapDataExporter.as" into that folder.
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 PMthank 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?
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
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 PMcan you please give me very simple php which will rename the imageID?
thanks
http://www.google.com/search?q=php+rename+file
Posted by: Mario Klingemann on December 29, 2007 04:38 PMHi hi,
When i change BitmapExporter.gatewayURL= http://localhost/... to BitmapExporter.gatewayURL= http://mysite.com/...
it's not work????
T.T
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 PMHíc híc 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
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 AMHi 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 AMThat 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 AMSweet, 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 PMHi again Mario
I am just using the temp file so store the image, I dont need to save it to a local computer, I read the comments above on what I should do for that.
My fla is outputing another file that is saved and I would like to use the same variablename for the image too. Since that name has a unique name how can I make the tmp files save with that unique name?
Hey im trying to get this to save the file locally. I.E. On the server. And not send it to the user. SO far i see that its saving to a temp folder. Is there any way i can pass a name to the file through flash?
Posted by: Eli on January 21, 2008 09:18 PMhello
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Áåñïìëàòíàÿ óèêàëüíàÿ ïîðíóõà
Áåñïëàòíîå ïîðíî - õóèñîñåè.óð
ñêà÷àòü ïîðíî íàõàëÿâó
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 PMOf 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 AMIn 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 PMHi 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 AMSo 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 PMMario,
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 PMHello 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
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 AMHello 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
hello mario,
im experincing some problems putting these file together.
could you tell how they should be uploaded to a server. many thank
james
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 PMi 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 PMHi 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
Just found the bug - and my apologies - its in my code...
Posted by: Karim on March 28, 2008 04:23 PMHi , i need to know can we save the image as 300 DPI
and how ?
Thanx
Posted by: bilal on April 3, 2008 01:34 PMHi 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 AMHi 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 AMIf 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 AMHi Mario,
i'm trying to create