Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Image Encode #42

Open
fisker opened this issue Jul 12, 2019 · 0 comments
Open

Simple Image Encode #42

fisker opened this issue Jul 12, 2019 · 0 comments

Comments

@fisker
Copy link
Owner

fisker commented Jul 12, 2019

function reverseImage(image) {
  const canvas  = document.createElement('canvas')
  const {width, height} = image
  Object.assign(canvas, {width, height})
  const context= canvas.getContext('2d')
  context.drawImage(image, 0, 0)
  const {data} = context.getImageData(0, 0, width, height)
  const imageData = new ImageData(
    new Uint8ClampedArray(
      Array.from(data).map(x => 255 - x).reverse()
    ), 
    height, 
    width
  )

  Object.assign(canvas,{width: height, height: width})
  context.putImageData(imageData, 0, 0)
  return canvas
}

function simpleImageEncode(imageUrl) {
  return new Promsie(resolve => {
    const image = new Image()
    image.src = imageUrl
    image.onload = () => {
      resolve(reverseImage(image))
    }
  })
}

Update: not safe, alpha value postion can't change, will lost color, should only switch postion of rgb value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant