Skip to content

Instantly share code, notes, and snippets.

@rssilva
Last active December 1, 2018 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rssilva/ade348dd4014f3d5962ff4d9a179d26f to your computer and use it in GitHub Desktop.
Save rssilva/ade348dd4014f3d5962ff4d9a179d26f to your computer and use it in GitHub Desktop.
// doing a query to get the element on html file
const canvas = document.querySelector('#canvas')
// getting the canvas context
const context = canvas.getContext('2d')
// Let's create an Image instance
const baseImage = new Image()
// 'low.jpg' is the image path on your file system
baseImage.src = 'low.jpg'
// callback that will be called when the image is loaded
baseImage.onload = () => {
// getting the width and height from canvas
const { width, height } = context.canvas
// drawing the image on the canvas
context.drawImage(baseImage, 0, 0, width, height)
// this method will return the data from the drawed image
const imageData = context.getImageData(0, 0, width, height)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment