i'm trying to make an javascript image color picker. It is possible to open local image in canvas, without uploading it to server ?
function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
var img = new Image();
img.onload = function(){
ctx.drawImage(img,0,0);
}
img.src = $('#uploadimage').val();
}
<input type='file' name='img' size='65' id='uploadimage' />
Go to your Canvas Course In your page, click on the embed image button (1) to quickly choose and upload an image saved on your computer. Click on the drop down arrow to the right of the embed image button to access images in your Course and User Files (2). A popup will appear to choose your image.
To get the image data URL of the canvas, we can use the toDataURL() method of the canvas object which converts the canvas drawing into a 64 bit encoded PNG URL. If you'd like for the image data URL to be in the jpeg format, you can pass image/jpeg as the first argument in the toDataURL() method.
Not supported in all browser (IE and Opera AFAIK) but you could get a data URI using the File API
function draw() {
var ctx = document.getElementById('canvas').getContext('2d')
, img = new Image()
, f = document.getElementById("uploadimage").files[0]
, url = window.URL || window.webkitURL
, src = url.createObjectURL(f);
img.src = src;
img.onload = function(){
ctx.drawImage(img,0,0);
url.revokeObjectURL(src);
}
}
<input type='file' name='img' size='65' id='uploadimage' />
I added a fiddle here as an example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With