-
Notifications
You must be signed in to change notification settings - Fork 52
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
Yan Heng
committed
Aug 2, 2023
1 parent
a1c83f9
commit b3a7395
Showing
4 changed files
with
59 additions
and
1 deletion.
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
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,13 @@ | ||
import Konva from 'konva'; | ||
|
||
export class Image extends Konva.Image { | ||
constructor(config: Konva.ImageConfig) { | ||
super(config); | ||
} | ||
|
||
public draw(): this { | ||
return super.draw(); | ||
} | ||
} | ||
|
||
export default Image; |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { selectFile } from '@pictode/utils'; | ||
|
||
import { Image as Img } from '../customs/image'; | ||
import { Tool } from '../types'; | ||
|
||
import { selectTool } from './select-tool'; | ||
|
||
export const imageTool = (): Tool => { | ||
const imageObject = new Image(); | ||
const img = new Img({ | ||
image: imageObject, | ||
stroke: 'black', | ||
strokeWidth: 2, | ||
}); | ||
|
||
return { | ||
name: 'imageTool', | ||
onActive(app) { | ||
app.cancelSelect(); | ||
selectFile(['.jpg', '.png', '.jpge', '.PNG', '.JPG', '.JPGE'], false).then((files) => { | ||
const fileReader = new FileReader(); | ||
fileReader.onload = (event) => { | ||
const fileDataUrl = event.target?.result as string; | ||
imageObject.src = fileDataUrl ?? ''; | ||
}; | ||
fileReader.readAsDataURL(files[0]); | ||
}); | ||
app.add(img); | ||
app.setTool(selectTool(img)); | ||
}, | ||
}; | ||
}; | ||
|
||
export default imageTool; |