-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
99 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const canvasToJpeg = async (canvas: HTMLCanvasElement, quality?: number): Promise<ArrayBuffer> => { | ||
const arrayBuffer = await new Promise<ArrayBuffer>((resolve) => { | ||
canvas.toBlob( | ||
(blob) => { | ||
if (!blob) { | ||
throw new Error('Failed to convert canvas to blob'); | ||
} | ||
const reader = new FileReader(); | ||
reader.onload = () => { | ||
if (reader.result instanceof ArrayBuffer) { | ||
resolve(reader.result); | ||
} else { | ||
throw new Error('Failed to convert canvas to ArrayBuffer'); | ||
} | ||
}; | ||
reader.readAsArrayBuffer(blob); | ||
}, | ||
'image/jpeg', | ||
(quality || 1) / 100 | ||
); | ||
}); | ||
// remove the original canvas | ||
canvas.width = 0; | ||
canvas.height = 0; | ||
canvas.remove(); | ||
return arrayBuffer; | ||
}; | ||
|
||
export default canvasToJpeg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import saveAs from 'file-saver'; | ||
|
||
const downloadOneFile = async (file: { name: string; buffer: ArrayBuffer }): Promise<void> => { | ||
saveAs(new Blob([file.buffer], { type: 'image/webp' }), file.name.replace(/\.[^/.]+$/, '.webp')); | ||
const downloadOneFile = async (file: { name: string; buffer: ArrayBuffer; type: 'image/jpeg' | 'image/webp' }): Promise<void> => { | ||
saveAs(new Blob([file.buffer], { type: file.type }), file.name.replace(/\.[^/.]+$/, `.${file.type === 'image/jpeg' ? 'jpg' : 'webp'}`)); | ||
}; | ||
|
||
export default downloadOneFile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Icon } from 'konsta/react'; | ||
import { SiJpeg } from 'react-icons/si'; | ||
|
||
interface JpegIconProps { | ||
size?: number; | ||
} | ||
|
||
const JpegIcon = ({ size }: JpegIconProps) => { | ||
return <Icon ios={<SiJpeg size={size} />} />; | ||
}; | ||
|
||
export default JpegIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
web/src/pages/root/components/export-to-jpeg.list-item.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ListItem, Toggle } from 'konsta/react'; | ||
import { useStore } from '../../../store'; | ||
import { useTranslation } from 'react-i18next'; | ||
import JpegIcon from '../../../icons/jpeg.icon'; | ||
|
||
const ExportToJpegListItem = () => { | ||
const { t } = useTranslation(); | ||
const { exportToJpeg, setExportToJpeg } = useStore(); | ||
|
||
return ( | ||
<> | ||
<ListItem | ||
title={t('root.settings.export-to-jpeg')} | ||
media={<JpegIcon size={26} />} | ||
after={<Toggle checked={exportToJpeg} onChange={() => setExportToJpeg(!exportToJpeg)} />} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default ExportToJpegListItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters