Skip to content

Commit

Permalink
feat: Add support webp (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
정현 committed Mar 29, 2024
2 parents 3558cfe + 9ec50e3 commit 6b54682
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
18 changes: 18 additions & 0 deletions web/src/components/ExportToWebpToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Toggle } from 'konsta/react';
import { useEffect, useState } from 'react';

const ExportToWebpToggle = () => {
const [exportToWebp, setExportToWebp] = useState(localStorage.getItem('exportToWebp') || 'no');

useEffect(() => {
localStorage.setItem('exportToWebp', exportToWebp);
}, [exportToWebp]);

return (
<>
<Toggle checked={exportToWebp === 'yes'} onChange={() => setExportToWebp(exportToWebp === 'yes' ? 'no' : 'yes')} />
</>
);
};

export default ExportToWebpToggle;
4 changes: 2 additions & 2 deletions web/src/frames/cinemaScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export async function cinemaScope(photo: Photo) {
trimmedImageHeight
);

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

await new Promise((resolve) => setTimeout(resolve, 1000));
Expand Down
4 changes: 2 additions & 2 deletions web/src/frames/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export async function simpleFrame(photo: Photo) {
textVerticalCenter + LINE_SPACING + FONT_SIZE
);

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

await new Promise((resolve) => setTimeout(resolve, 1000));
Expand Down
4 changes: 2 additions & 2 deletions web/src/frames/square.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ export async function squareFrame(photo: Photo) {
textVerticalCenter + LINE_SPACING + FONT_SIZE
);

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

await new Promise((resolve) => setTimeout(resolve, 1000));
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/SettingPage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { BlockTitle, List, ListItem } from 'konsta/react';
import DarkModeToggle from '../components/DarkModeToggle';
import ExportToWebpToggle from '../components/ExportToWebpToggle';

const SettingPage = () => {
return (
<>
<BlockTitle>Customize</BlockTitle>
<List strong inset>
<ListItem label title="Enable Dark Mode" after={<DarkModeToggle />} />
<ListItem label title="Export to Webp" after={<ExportToWebpToggle />} />
</List>
</>
);
Expand Down

0 comments on commit 6b54682

Please sign in to comment.