diff --git a/package.json b/package.json index fd6b676..8bb629f 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", + "merge-images": "^2.0.0", "react": "^17.0.1", "react-dom": "^17.0.1", "react-scripts": "4.0.1", diff --git a/src/App.js b/src/App.js index 3784575..4982d88 100644 --- a/src/App.js +++ b/src/App.js @@ -1,25 +1,66 @@ -import logo from './logo.svg'; -import './App.css'; +import { useState, useEffect, useCallback } from 'react' +import './App.css' + +import frame_mixed from './frames/ProfileFrame Mixed Bars.png' + +import mergeImages from 'merge-images' + +const frameSize = 1080 function App() { - return ( + const [photo, setPhoto] = useState(null) + const [combinedImage, setCombinedImage] = useState(null) + + const handleImage = useCallback(files_event => { + const reader = new FileReader() + reader.onload = reader_event => { + const img = new Image() + img.onload = function () { + const offscreenCanvas = document.createElement('canvas') + offscreenCanvas.width = frameSize + offscreenCanvas.height = frameSize + + const offscreenCanvas_ctx = offscreenCanvas.getContext('2d', { alpha: false }) + + const width = frameSize + const height = (img.height / img.width) * frameSize + offscreenCanvas_ctx.drawImage( + img, + (frameSize - width) / 2, + (frameSize - height) / 2, + width, + height, + ); + + const pngUrl = offscreenCanvas.toDataURL() + setPhoto(pngUrl) + } + img.src = reader_event.target.result + } + reader.readAsDataURL(files_event.target.files[0]) + }, [setPhoto]) + + useEffect(() => { + mergeImages([ + ...(photo ? [photo] : []), + ...(frame_mixed ? [frame_mixed] : []), + ]) + .then(b64 => setCombinedImage(b64)) + }, [photo]) + + + +return (
- Edit src/App.js
and save to reload.
-