I am attempting to allow users to upload their image file through DOM file uploader ( that is <input type="file"></input>
) but after I do that I am unsure how to move the image to JavaScript and process it using p5.js. How do I convert an HTML file to a p5.js file or an array of pixels, or really anything I can work with or read as values in JavaScript?
First I restricted the element to only accept .png
and .jpg
files.
Then I tried using .file[0]
syntax and tried to load the image through its path using .value
inside of the loadImage()
function.
Neither works, and I am just generally unsure as to what to do from this point.
<div id="uploadMenu">
<h4>Please select your image file:</h4>
<input accept=".png, .jpg, .jpeg" type="file" id="imageUpload">
<button onclick="fileToGrid()">Done</button>
<script>
</script>
<script>
let thisWindow = document.getElementById("uploadMenu");
let windowWidth = thisWindow.style.width;
console.log(windowWidth);
thisWindow.style.left = `${innerWidth/2 - 100}px`
thisWindow.style.top = `${innerHeight/2 - 50}px`
</script>
</div>
function fileToGrid() {
let uploadFromHTML = document.getElementById("imageUpload");
let uploadedImage = loadImage(uploadFromHTML.value);
let imageW = uploadedImage.width;
let imageH = uploadedImage.height;
console.log(imageW, imageH);
// the end goal is to convert this image to an array of its pixel values
}