-
Notifications
You must be signed in to change notification settings - Fork 22
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
14 changed files
with
239 additions
and
70 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
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
Binary file not shown.
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,38 @@ | ||
html, | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
font: 14px/1.5em Arial, Verdana, sans-serif; | ||
} | ||
|
||
.header { | ||
position: relative; | ||
z-index: 1000; | ||
display: flex; | ||
width: 100%; | ||
background: #474747; | ||
color: #fff; | ||
} | ||
.header.bb { | ||
border-bottom: 4px solid #252525; | ||
} | ||
.header-title { | ||
flex: 1; | ||
padding: 10px; | ||
} | ||
.header-title h1 { | ||
margin: 0; | ||
padding: 0; | ||
font-size: 14px; | ||
font-weight: normal; | ||
} | ||
.header-links { | ||
padding: 10px; | ||
} | ||
.header-links a { | ||
color: #fff; | ||
text-decoration: underline; | ||
} | ||
.header-links a:hover { | ||
text-decoration: none; | ||
} |
Binary file not shown.
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,64 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>🔲 Crop Example - Mini Canvas Editor</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> | ||
<link rel="icon" href="./assets/favicon.ico" /> | ||
<link href="./assets/common.css" rel="stylesheet" /> | ||
<style> | ||
body { | ||
background: url('./assets/background-pattern.svg'); | ||
} | ||
p { | ||
text-align: center; | ||
margin: 0; | ||
padding: 10px 0; | ||
} | ||
#editor-placeholder { | ||
margin: 0 auto; | ||
width: 50vw; | ||
height: 50vh; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3); | ||
} | ||
@media only screen and (max-width: 600px) { | ||
#editor-placeholder { | ||
width: 100%; | ||
} | ||
} | ||
#save-button { | ||
border: 0; | ||
padding: 10px 20px; | ||
color: #fff; | ||
background: navy; | ||
cursor: pointer; | ||
border-radius: 5px; | ||
} | ||
#save-button:hover { | ||
opacity: 0.8; | ||
} | ||
a { | ||
color: navy; | ||
} | ||
a:hover { | ||
text-decoration: none; | ||
} | ||
</style> | ||
<script src="./builds/crop.js" defer></script> | ||
</head> | ||
<body> | ||
<header class="header"> | ||
<div class="header-title"> | ||
<h1>🔲 Crop Example</h1> | ||
</div> | ||
<div class="header-links"> | ||
<a href="https://github.com/img-js/mini-canvas-editor" target="_blank">Mini Canvas Editor</a> | ||
</div> | ||
</header> | ||
|
||
<div id="editor-placeholder"></div> | ||
<p> | ||
<button id="save-button">💾 Save cropped image</button> | ||
</p> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Editor, EditorMode } from 'mini-canvas-editor'; | ||
|
||
import 'mini-canvas-editor/css/editor.css'; | ||
|
||
export class App { | ||
public static preload() { | ||
const preloader = new Image(); | ||
preloader.src = './assets/cat.jpg'; | ||
preloader.onload = () => App.create(preloader); | ||
} | ||
|
||
public static create(image: HTMLImageElement) { | ||
const placeholder = document.getElementById('editor-placeholder') as HTMLElement; | ||
const saveButton = document.getElementById('save-button') as HTMLElement; | ||
|
||
const editor = Editor.createFromImage( | ||
placeholder, | ||
image, | ||
{ | ||
workspaceHeight: 160, | ||
workspaceWidth: 200, | ||
fitToWorkspace: true, | ||
select: true | ||
}, | ||
{ | ||
initialMode: EditorMode.select, | ||
brush: false, | ||
rect: false, | ||
image: false, | ||
textbox: false, | ||
sidebar: false | ||
} | ||
); | ||
const app = new App(editor); | ||
saveButton.addEventListener('click', app.onSaveClicked, false); | ||
return app; | ||
} | ||
|
||
private constructor(private readonly editor: Editor) {} | ||
|
||
private readonly onSaveClicked = () => { | ||
const a = document.createElement('a'); | ||
a.download = 'crop.png'; | ||
a.href = this.editor.render().toDataURL('image/png'); | ||
a.click(); | ||
}; | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', App.preload, false); |
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
Oops, something went wrong.