mirror of
https://github.com/voltbonn/profile-picture-generator.git
synced 2024-12-22 07:45:04 +00:00
corrected the image fitting to cover the frame-area
This commit is contained in:
parent
2dd926cbbb
commit
5c358d7d53
1 changed files with 10 additions and 3 deletions
13
src/App.js
13
src/App.js
|
@ -27,10 +27,17 @@ function App() {
|
||||||
offscreenCanvas.width = frameSize
|
offscreenCanvas.width = frameSize
|
||||||
offscreenCanvas.height = frameSize
|
offscreenCanvas.height = frameSize
|
||||||
|
|
||||||
|
|
||||||
const width = frameSize
|
|
||||||
const height = (img.height / img.width) * frameSize
|
|
||||||
const offscreenCanvas_ctx = offscreenCanvas.getContext('2d', { alpha: true })
|
const offscreenCanvas_ctx = offscreenCanvas.getContext('2d', { alpha: true })
|
||||||
|
|
||||||
|
let width, height;
|
||||||
|
if (img.width < img.height) {
|
||||||
|
height = (img.height / img.width) * frameSize
|
||||||
|
width = frameSize
|
||||||
|
} else {
|
||||||
|
height = frameSize
|
||||||
|
width = (img.width / img.height) * frameSize
|
||||||
|
}
|
||||||
|
|
||||||
offscreenCanvas_ctx.drawImage(
|
offscreenCanvas_ctx.drawImage(
|
||||||
img,
|
img,
|
||||||
(frameSize - width) / 2,
|
(frameSize - width) / 2,
|
||||||
|
|
Loading…
Reference in a new issue