-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SaveAs tool and example #34
Conversation
Is it possible to use any of this code for send the binary image over HTTP, for example using |
Yeah, sure, but what for? You want to save the canvas as an image on your server? I think you can just use canvas.toDataURL(); and then POST that data to the server. Then you just decode the base64 string to produce an image on the server. |
Yes, exactly. I want to save the save the canvas (which has all of the user's modifications, transforms and annotations) to the server. This along with #30 so that I have both the steps to re-create the modifications and the image of the canvas. |
Ok so you want to use the image to show the saved-state then. Seems easy enough to do, but I don't know if it's worth having extra code for it in cornerstone itself. // Get the canavas
var canvas = $(element).find("canvas").get(0);
var imageData = canvas.toDataURL();
$.ajax({
method: "POST",
url: "/your/server/",
data: {"image": imageData}
}) Then on the server (at least in Python): import base64
# Assuming you have a request like in Django
data = request.POST["image"]
filename = "MyNewImage.png"
out_file = open(filename, "w")
out_file.write(base64.decodestring(data))
out_file.close() Hope that helps |
Sure that seems simple enough. I do think though that a save as tool for in browser saves still stands on its own as a useful feature. |
|
||
function saveAs(element, filename) | ||
{ | ||
var canvas = $(element).find("canvas").get(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to extract $(element).find("canvas").get(0);
as a helper method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not, it's boilerplate jQuery.
Small function for saving PNG files from the canvases. Addresses #31.
Seems it can't be automatically merged because of changes to dist/cornerstoneTools... How should we approach this? I assume I stop using grunt before commits? But then the rawgit examples won't work...Update: Rebased and fixed