Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <input id="bild" multiple="" name="bild" type="file">
- $( "input#bild" ).change(function() {
- console.log("multiple");
- // from an input element
- var filesToUpload = this.files;
- //console.log(filesToUpload);
- if(typeof this.files[0] !== "undefined") {
- console.log("multiple-1");
- var img = document.createElement("img");
- img.src = window.URL.createObjectURL(this.files[0]);
- $( img ).load(function() {
- console.log("multiple-1-loaded");
- canvas = $("#uploading_canvas_image_1").get(0);
- var MAX_WIDTH = 550;
- var MAX_HEIGHT = 400;
- var width = img.width;
- var height = img.height;
- if (width > height) {
- if (width > MAX_WIDTH) {
- height *= MAX_WIDTH / width;
- width = MAX_WIDTH;
- }
- } else {
- if (height > MAX_HEIGHT) {
- width *= MAX_HEIGHT / height;
- height = MAX_HEIGHT;
- }
- }
- canvas.width = width;
- canvas.height = height;
- var ctx = canvas.getContext("2d");
- ctx.drawImage(img, 0, 0, width, height);
- var dataurl = canvas.toDataURL("image/jpg");
- $( "#dataurl_image_1" ).val(dataurl);
- });
- }
- if(typeof this.files[1] !== "undefined") {
- console.log("multiple-2");
- var img = document.createElement("img");
- img.src = window.URL.createObjectURL(this.files[1]);
- $( img ).load(function() {
- console.log("multiple-2-loaded");
- canvas = $("#uploading_canvas_image_2").get(0);
- var MAX_WIDTH = 550;
- var MAX_HEIGHT = 400;
- var width = img.width;
- var height = img.height;
- if (width > height) {
- if (width > MAX_WIDTH) {
- height *= MAX_WIDTH / width;
- width = MAX_WIDTH;
- }
- } else {
- if (height > MAX_HEIGHT) {
- width *= MAX_HEIGHT / height;
- height = MAX_HEIGHT;
- }
- }
- canvas.width = width;
- canvas.height = height;
- var ctx = canvas.getContext("2d");
- ctx.drawImage(img, 0, 0, width, height);
- var dataurl = canvas.toDataURL("image/jpg");
- $( "#dataurl_image_2" ).val(dataurl);
- });
- }
- if(typeof this.files[2] !== "undefined") {
- console.log("multiple-3");
- var img = document.createElement("img");
- img.src = window.URL.createObjectURL(this.files[2]);
- $( img ).load(function() {
- console.log("multiple-3-loaded");
- canvas = $("#uploading_canvas_image_3").get(0);
- var MAX_WIDTH = 550;
- var MAX_HEIGHT = 400;
- var width = img.width;
- var height = img.height;
- if (width > height) {
- if (width > MAX_WIDTH) {
- height *= MAX_WIDTH / width;
- width = MAX_WIDTH;
- }
- } else {
- if (height > MAX_HEIGHT) {
- width *= MAX_HEIGHT / height;
- height = MAX_HEIGHT;
- }
- }
- canvas.width = width;
- canvas.height = height;
- var ctx = canvas.getContext("2d");
- ctx.drawImage(img, 0, 0, width, height);
- var dataurl = canvas.toDataURL("image/jpg");
- $( "#dataurl_image_3" ).val(dataurl);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement