์ด๋ฏธ์ง ์๋ํฐ
@inkio/image-editor๋ ์๋ฅด๊ธฐ, ํ์ , ํฌ๊ธฐ ์กฐ์ , ๊ทธ๋ฆฌ๊ธฐ, ๋ํ, ํ
์คํธ ์ฃผ์ ๊ธฐ๋ฅ์ ๊ฐ์ถ
๋
๋ฆฝ ์ด๋ฏธ์ง ํธ์ง๊ธฐ์
๋๋ค. ์๋ํฐ์ ์ด๋ฏธ์ง ๋ธ๋ก์ ์ฐ๊ฒฐํ๊ฑฐ๋ ๋จ๋
์ปดํฌ๋ํธ๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค.
์ค์น์ CSS
์ด๋ฏธ์ง ์๋ํฐ๋ ์์ฒด ์คํ์ผ์ํธ๊ฐ ํ์ํฉ๋๋ค. ์ฑ ์ง์ ์ ์์ ํ ๋ฒ import ํ์ธ์.
import '@inkio/image-editor/style.css';์๋ํฐ์ ์ฐ๊ฒฐํ๊ธฐ
@inkio/editor(๋๋ @inkio/simple)์ imageBlock.imageEditor ์ต์
์ ImageEditorModal์
์ ๋ฌํ๋ฉด ์ด๋ฏธ์ง ํด๋ฐ์ ํธ์ง ๋ฒํผ์ด ๋ํ๋ฉ๋๋ค. ๋ฒํผ์ ๋๋ฅด๋ฉด ๋ชจ๋ฌ์ด ์ด๋ฆฌ๊ณ , ์ ์ฅ ์
ํธ์ง ๊ฒฐ๊ณผ๊ฐ ํด๋น ์ด๋ฏธ์ง ๋ธ๋ก์ ๋ฐ์๋ฉ๋๋ค.
import { Editor } from '@inkio/editor';
import { ImageEditorModal } from '@inkio/image-editor';
import '@inkio/editor/style.css';
import '@inkio/image-editor/style.css';
export function Page() {
return (
<Editor
onImageUpload={async (file) => URL.createObjectURL(file)}
imageBlock={{ imageEditor: ImageEditorModal }}
/>
);
}imageEditor์๋ { isOpen, imageSrc, onSave, onClose } ์ธํฐํ์ด์ค๋ฅผ ๋ง์กฑํ๋ ์ปดํฌ๋ํธ๋ผ๋ฉด
๋ฌด์์ด๋ ์ ๋ฌํ ์ ์์ผ๋ฉฐ, ImageEditorModal์ด ๊ธฐ๋ณธ ๊ตฌํ์
๋๋ค.
ImageEditorModal props
| Prop | ํ์ | ์ค๋ช |
|---|---|---|
isOpen | boolean | ๋ชจ๋ฌ ์ด๋ฆผ ์ฌ๋ถ (ํ์) |
imageSrc | string | ํธ์งํ ์ด๋ฏธ์ง ์์ค (ํ์) |
onSave | (editedImageData: string) => void | ์ ์ฅ ์ ํธ์ง๋ data URL ์ฝ๋ฐฑ (ํ์) |
onClose | () => void | ๋ซ๊ธฐ ์ฝ๋ฐฑ (ํ์) |
theme | 'light' | 'dark' | ์์ ํ
๋ง (๋ฏธ์ง์ ์ .inkio ๋ฃจํธ์ ํ
๋ง๋ฅผ ๋ฐ๋ฆ) |
imageQuality | number | ์ถ๋ ฅ ํ์ง 0~1 (๊ธฐ๋ณธ๊ฐ: 0.92) |
imageFormat | 'png' | 'jpeg' | 'webp' | ์ถ๋ ฅ ํ์ (๊ธฐ๋ณธ๊ฐ: 'png') |
tools | ToolType[] | ๋ ธ์ถํ ๋๊ตฌ ๋ชฉ๋ก |
locale | string | Partial<ImageEditorLocale> | ๋ก์ผ์ผ ID ๋๋ ๋ผ๋ฒจ ์ค๋ฒ๋ผ์ด๋ |
messages | InkioImageEditorMessageOverrides | InkioMessageOverrides | ๋ฉ์์ง ์ค๋ฒ๋ผ์ด๋ |
icons | Partial<InkioIconRegistry> | ์์ด์ฝ ์ค๋ฒ๋ผ์ด๋ |
๋จ๋ ์ปดํฌ๋ํธ ์ฌ์ฉ
๋ชจ๋ฌ ์์ด ์ธ๋ผ์ธ ํธ์ง ํ๋ฉด์ ์ง์ ๋ฐฐ์นํ๋ ค๋ฉด ImageEditor๋ฅผ ์ฌ์ฉํฉ๋๋ค.
import { ImageEditor } from '@inkio/image-editor';
import '@inkio/image-editor/style.css';
export function StandaloneEditor({ src }: { src: string }) {
return (
<ImageEditor
src={src}
onSave={(dataUrl) => console.log('saved', dataUrl)}
onCancel={() => console.log('cancelled')}
/>
);
}ImageEditor props
| Prop | ํ์ | ์ค๋ช |
|---|---|---|
src | string | ํธ์งํ ์ด๋ฏธ์ง ์์ค (ํ์) |
onSave | (dataUrl: string) => void | ์ ์ฅ ์ ํธ์ง๋ data URL ์ฝ๋ฐฑ (ํ์) |
onCancel | () => void | ์ทจ์ ์ฝ๋ฐฑ (ํ์) |
outputFormat | 'png' | 'jpeg' | 'webp' | ์ถ๋ ฅ ํ์ (๊ธฐ๋ณธ๊ฐ: 'png') |
outputQuality | number | ์ถ๋ ฅ ํ์ง 0~1 |
tools | ToolType[] | ๋ ธ์ถํ ๋๊ตฌ ๋ชฉ๋ก |
defaultTool | ToolType | ์ด๊ธฐ ์ ํ ๋๊ตฌ |
locale | Partial<ImageEditorLocale> | ๋ผ๋ฒจ ์ค๋ฒ๋ผ์ด๋ |
className | string | ๋ฃจํธ ์๋ฆฌ๋จผํธ ํด๋์ค |
maxUndoSteps | number | ์คํ ์ทจ์ ๊ธฐ๋ก ํ๋ (๊ธฐ๋ณธ๊ฐ: 30) |
onDirtyChange | (dirty: boolean) => void | ๋ฏธ์ ์ฅ ๋ณ๊ฒฝ ๋ฐ์/ํด์ ์ฝ๋ฐฑ |
๋๊ตฌ์ ์ฃผ์
ToolType์ ๋ค์ ๋๊ตฌ๋ฅผ ์ ์ํฉ๋๋ค.
type ToolType = 'crop' | 'rotate' | 'resize' | 'draw' | 'shape' | 'text';cropโ ์๋ฅด๊ธฐ ์์ญ ์ง์ rotateโ ํ์ ๋ฐ ์ข์ฐ/์ํ ๋ฐ์ resizeโ ์ถ๋ ฅ ํฌ๊ธฐ ์กฐ์ drawโ ์์ ๊ทธ๋ฆฌ๊ธฐ (๋ธ๋ฌ์)shapeโ ์ฌ๊ฐํ, ํ์, ํ์ดํ, ์ ๋ํtextโ ํ ์คํธ ์ฃผ์
tools๋ฅผ ์ง์ ํ์ง ์์ผ๋ฉด ๊ธฐ๋ณธ ๋ชฉ๋ก(['resize', 'draw', 'shape', 'text', 'rotate'])์ด ์ฌ์ฉ๋ฉ๋๋ค.
<ImageEditor src={src} tools={['draw', 'text']} onSave={save} onCancel={cancel} />๊ทธ๋ฆฌ๊ธฐยท๋ํยทํ
์คํธ๋ก ์ถ๊ฐํ ํญ๋ชฉ์ ์ฃผ์(annotation)์ผ๋ก ๊ด๋ฆฌ๋ฉ๋๋ค. ๋ชจ๋ ์ฃผ์ ํ์
์
Annotation ์ ๋์จ์ผ๋ก export๋ฉ๋๋ค.
| ํ์ | ์ค๋ช |
|---|---|
RectAnnotation | ์ฌ๊ฐํ ๋ํ |
EllipseAnnotation | ํ์ ๋ํ |
ArrowAnnotation | ํ์ดํ |
LineAnnotation | ์ง์ |
TextAnnotationData | ํ ์คํธ ์ฃผ์ |
FreeDrawAnnotation | ์์ ๊ทธ๋ฆฌ๊ธฐ ์ |
์ด ์ธ์ CropRect, Transform, DrawOptions, ShapeOptions, TextOptions,
ImageEditorState ๋ฑ์ ๋ณด์กฐ ํ์
๋ ํจ๊ป export๋ฉ๋๋ค.
i18n
์ด๋ฏธ์ง ์๋ํฐ๋ @inkio/core์ ๋์ผํ ๋ฉ์์ง ์ฒด๊ณ๋ฅผ ๋ฐ๋ฆ
๋๋ค. ๋๊ตฌ ๋ผ๋ฒจ ๋ฑ UI ํ
์คํธ๋
๋ค์ ํฌํผ๋ก ์กฐํยท์ค๋ฒ๋ผ์ด๋ํฉ๋๋ค.
import {
enImageEditorMessages,
resolveImageEditorMessages,
mergeImageEditorMessages,
toImageEditorMessageOverrides,
} from '@inkio/image-editor';| Export | ์ค๋ช |
|---|---|
enImageEditorMessages | ๊ธฐ๋ณธ(์์ด) ๋ฉ์์ง ์ธํธ |
resolveImageEditorMessages | ๋ก์ผ์ผ ์ ๋ ฅ๊ณผ ์ค๋ฒ๋ผ์ด๋๋ฅผ ๋ณํฉํด ๋ฉ์์ง ์ธํธ๋ฅผ ๋ฐํ |
mergeImageEditorMessages | ์ฌ๋ฌ ์ค๋ฒ๋ผ์ด๋๋ฅผ ์์๋๋ก ๋ณํฉ |
toImageEditorMessageOverrides | InkioMessageOverrides์์ ์ด๋ฏธ์ง ์๋ํฐ ์ค๋ฒ๋ผ์ด๋๋ฅผ ์ถ์ถ |
๊ฐ๋จํ ๋ผ๋ฒจ๋ง ๋ฐ๊พธ๋ ค๋ฉด ImageEditorModal/ImageEditor์ locale prop์
Partial<ImageEditorLocale> ๊ฐ์ฒด๋ฅผ ์ง์ ์ ๋ฌํด๋ ๋ฉ๋๋ค.
<ImageEditorModal
isOpen={isOpen}
imageSrc={src}
onSave={onSave}
onClose={onClose}
locale={{ save: '์ ์ฅ', cancel: '์ทจ์' }}
/>