1
0
Fork 0
mirror of https://github.com/voltbonn/profile-picture-generator.git synced 2024-12-22 15:55:08 +00:00

renamed offscreenCanvas to canvas

and renamed offscreenCanvas_ctx to ctx
This commit is contained in:
thomasrosen 2021-01-22 08:39:49 +01:00
parent 041805a9d5
commit f1cccb6879

View file

@ -28,11 +28,11 @@ function App() {
reader.onload = reader_event => { reader.onload = reader_event => {
const img = new Image() const img = new Image()
img.onload = function () { img.onload = function () {
const offscreenCanvas = document.createElement('canvas') const canvas = document.createElement('canvas')
offscreenCanvas.width = frameSize canvas.width = frameSize
offscreenCanvas.height = frameSize canvas.height = frameSize
const offscreenCanvas_ctx = offscreenCanvas.getContext('2d', { alpha: true }) const ctx = canvas.getContext('2d', { alpha: true })
let width, height; let width, height;
if (img.width < img.height) { if (img.width < img.height) {
@ -43,7 +43,7 @@ function App() {
width = (img.width / img.height) * frameSize width = (img.width / img.height) * frameSize
} }
offscreenCanvas_ctx.drawImage( ctx.drawImage(
img, img,
(frameSize - width) / 2, (frameSize - width) / 2,
(frameSize - height) / 2, (frameSize - height) / 2,
@ -51,7 +51,7 @@ function App() {
height, height,
) )
const pngUrl = offscreenCanvas.toDataURL() const pngUrl = canvas.toDataURL()
setPhoto(pngUrl) setPhoto(pngUrl)
} }
img.src = reader_event.target.result img.src = reader_event.target.result