Skip to content

Commit

Permalink
feat: Add no frame (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
정현 committed Mar 29, 2024
2 parents 6b54682 + b5626a5 commit 6c8d8b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
29 changes: 29 additions & 0 deletions web/src/frames/no-frame.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Photo from '../domain/photo';

export async function noFrame(photo: Photo) {
return new Promise<void>((resolve) => {
const canvas = document.getElementById('canvas') as HTMLCanvasElement;
const context = canvas.getContext('2d') as CanvasRenderingContext2D;

const image = new Image();
image.src = photo.url;
image.onload = async () => {
canvas.width = photo.width;
canvas.height = photo.height;

context.fillStyle = '#ffffff';
context.fillRect(0, 0, canvas.width, canvas.height);
context.drawImage(image, 0, 0, photo.width, photo.height);

const data = canvas.toDataURL(localStorage.getItem('exportToWebp') === 'yes' ? 'image/webp' : 'image/jpeg');
const a = document.createElement('a');
a.href = data;
a.download = localStorage.getItem('exportToWebp') === 'yes' ? photo.name.replace(/\.[^/.]+$/, '.webp') : photo.name;
a.click();

await new Promise((resolve) => setTimeout(resolve, 1000));

resolve();
};
});
}
4 changes: 3 additions & 1 deletion web/src/pages/FramePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import PhotoUploadButton from '../components/PhotoUploadButton';
import { simpleFrame } from '../frames/simple';
import { squareFrame } from '../frames/square';
import { cinemaScope } from '../frames/cinemaScope';
import { noFrame } from '../frames/no-frame';

const FramePage = () => {
const frames = [
{ name: 'No Frame', func: noFrame },
{ name: 'Simple', func: simpleFrame },
{ name: 'Square', func: squareFrame },
{ name: 'CinemaScope', func: cinemaScope },
{ name: 'Cinema Scope', func: cinemaScope },
];

const [photos, setPhotos] = useState<Photo[]>([]);
Expand Down

0 comments on commit 6c8d8b1

Please sign in to comment.