UPDATE (March 2018): Hello people of the future! This answer still gets a lot of traffic and I noticed that the old JSFiddle I'd put together was broken so it's been updated. New JSFiddle showing this technique is here: https://jsfiddle.net/Sq7hg/1913.
--
You might want to look into a Flash-based solution if you can't use <canvas>
(though unless this specifically needs to work in old versions of IE I'm not sure why you can't).
http://flashcanvas.net/ is an emulation of <canvas>
using Flash that might get you where you need to go. The documentation says that it supports toDataURL()
so that might work for you.
Can you provide more insight into what your restrictions around <canvas>
are and what you've attempted to try already?
//EDIT
According to your comment below you might be able to use <canvas>
, in which case you can try using http://html2canvas.hertzen.com – it's a JavaScript solution that basically re-writes the DOM of a specified part of your code to a <canvas>
and then allows you to interact with it however you want, including turning it into image data via toDataURL()
.
I've not used it before, but your JavaScript code would look something like this:
html2canvas([document.getElementById('mydiv')], {
onrendered: function(canvas) {
var data = canvas.toDataURL('image/png');
// AJAX call to send `data` to a PHP file that creates an image from the dataURI string and saves it to a directory on the server
}
});
I've knocked together a quick jsfiddle of this in action here: https://jsfiddle.net/Sq7hg/1913/ (note: updated link as per above)
This jsfiddle shows how to use the toDataURL()
method to convert the canvas to an image and append it to the document. Saving the generated image to a server is an infinitely more complex task as it will require an AJAX call or somesuch to send the image data to a PHP script that converts the generated data:
URL to an actual image and then saves it to a directory that you have permission to write to. If that's what you need to do, rather than going into that here I'd recommend starting with this Stack Overflow question: How to save an HTML5 Canvas as an image on a server?