I am trying to upload an image from my iPhone and use that image multiple times to draw to the canvas and then finally save the image (though I haven't implemented the saving part yet). I am using the example here: http://code.hootsuite.com/html5/ which I can get to work for just drawing the image, however, if I try to modify the image I get the cross-origin error. The image uploading and editing works fine with android devices on Chrome (but doesn't work with iPhone on Safari). Has anyone experienced a similar problem or can offer some solution to this?
if (window.File && window.FileReader && window.FormData) {
var inputField = document.getElementById('file');
inputField.addEventListener('change', function(e){
var file = e.target.files[0];
if (file) {
if (/^image\//i.test(file.type)) {
readFile(file);
} else {
alert('Not a valid image!');
}
}
})
} else {
alert("FILE UPLOAD NOT SUPPORTED");
}
function readFile(file) {
var reader = new FileReader();
reader.onloadend = function () {
console.log('reader.onloadend');
processFile(reader.result, file.type);
};
reader.onerror = function () {
alert('There was an error reading the file!');
};
reader.readAsDataURL(file);
}
function processFile(dataURL, fileType) {
var maxWidth = 600;
var maxHeight = 600;
var image = new Image();
image.src = dataURL;
image.onload = function () {
var width = image.width;
var height = image.height;
var shouldResize = (width > maxWidth) || (height > maxHeight);
main(image); // this passes image to function that draws image to canvas and crops
}