์ด ์น์ฌ์ดํธ๋ Next.js๋ฅผ ์ฌ์ฉํด ๋ง๋ค์ด์ก์ต๋๋ค.
์ธ์คํ๊ทธ๋จ์ ์์ ์ด ์ฐ์ ์ฌ์ง์ ์ฌ๋ฆด ๋, ์๋ณธ ๊ทธ๋๋ก ์ฌ๋ฆฌ๋ ๊ฒ ๋ณด๋ค ๊ทธ ์ฌ์ง์ EXIF(์
ํฐ ์คํผ๋, ์กฐ๋ฆฌ๊ฐ ๊ฐ, ISO๋ฑ)๋ฅผ ์
๋ ฅํด ๋์์ผ๋ก์จ ์ฌ๋๋ค์ด ์ ๋ณด๋ฅผ ์ ์ ์๊ฒ ๋๋ ํ๋ ์์ ๋ง๋๋ ๊ฒ์ด ์ ํ์ด๋ค.
๊ทธ๋ฌ๋, ์ด ์์
์ ํฌํ ์ต์ผ๋ก ์ผ์ผ์ด ์
๋ ฅํด์ผ ํ๋ค๋ ๊ฒ์ด ๋จ์ ์ด์๋ค. ๊ทธ๋์ ์ด ์์
์ Python ์ฝ๋๋ก ์๋ํํ์ฌ ์ฌ์ฉ์์๊ฒ ์ ๊ณตํ๋ฉด ๋์ฑ ํธ๋ฆฌํ๊ฒ ๋ค๋ ์๊ฐ์ ํ์ฌ ๋ง๋ค์๋ค.
๋จผ์ , ๋ก์ปฌ ์๋ฒ์์ ๋ค์์ ์ปค๋งจ๋๋ฅผ ์คํํ๋ค:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev๋ก์ปฌ ์ฃผ์ http://localhost:3000์ ์ ์ํ์ฌ ๊ฒฐ๊ณผ๋ฌผ์ ํ์ธํ๋ค.
function setupCanvas(imgWidth: number, imgHeight: number, padding: number, metadataHeight: number): {
canvas: HTMLCanvasElement;
ctx: CanvasRenderingContext2D;
canvasWidth: number;
canvasHeight: number;
scaledImgWidth: number;
scaledImgHeight: number;
imgX: number;
imgY: number;
} {
// ๊ณ ์ ์บ๋ฒ์ค ํฌ๊ธฐ
const canvasWidth = 1080 * 2;
const canvasHeight = 1350 * 2;
const canvas = document.createElement('canvas');
canvas.width = canvasWidth;
canvas.height = canvasHeight;
const ctx = canvas.getContext('2d');
if (!ctx) throw new Error('Could not get canvas context');
// ๋ฐฐ๊ฒฝ ์ค์
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
// ์ด๋ฏธ์ง ํฌ๊ธฐ ๊ณ์ฐ (์บ๋ฒ์ค์ ๋ง๊ฒ ์ค์ผ์ผ๋ง)
const imageArea = canvasHeight - (padding * 5) - metadataHeight;
const scale = Math.min(
(canvasWidth - padding * 2) / imgWidth,
imageArea / imgHeight
);
const scaledImgWidth = imgWidth * scale;
const scaledImgHeight = imgHeight * scale;
// ์ด๋ฏธ์ง ์์น ๊ณ์ฐ (๊ฐ๋ก ๋ฐ ์ธ๋ก ์ค์ ์ ๋ ฌ)
const imgX = (canvasWidth - scaledImgWidth) / 2;
// ๊ฐ๋ก ์ด๋ฏธ์ง(landscape)์ธ ๊ฒฝ์ฐ ์์ง ์ค์ ์ ๋ ฌ
let imgY = padding * 2;
if (imgWidth > imgHeight) {
// ๊ฐ๋ก ์ด๋ฏธ์ง๋ฉด ์์ง์ผ๋ก๋ ์ค์์ ๋ฐฐ์น
imgY = (canvasHeight - metadataHeight - scaledImgHeight) / 2;
}
return {
canvas,
ctx,
canvasWidth,
canvasHeight,
scaledImgWidth,
scaledImgHeight,
imgX,
imgY
};
}flowchart LR
A(ํ๋ก ํธ์๋)
B[์ฌ์ง์ ๋ฉํ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ]
C[canvas๋ฅผ ์ด์ฉํ์ฌ
ํฐ ๋ฐฐ๊ฒฝ ๋ง๋ค๊ธฐ]
D[์๋ณธ ์ฌ์ง์ ์ผ์ ํ
๋น์จ์ ๋ง์ถฐ resizeํ๊ธฐ]
E[ํฐ ๋ฐฐ๊ฒฝ์ resize๋ ์ฌ์ง๊ณผ
๋ฉํ ๋ฐ์ดํฐ ์
๋ ฅํ๊ธฐ]
A ---> |์ฌ์ง ์ ์ก| B
subgraph ๋ฐฑ์๋
B --- C --- D --- E
end
E ---> |์์ฑ๋ ์ด๋ฏธ์ง๋ฅผ base64๋ก
์ธ์ฝ๋ฉํ์ฌ returnํ๊ธฐ| A