-
Notifications
You must be signed in to change notification settings - Fork 19
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
29 changed files
with
464 additions
and
77 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,43 @@ | ||
name: examples | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ${{matrix.os}} | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v3 | ||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 18 | ||
- uses: pnpm/action-setup@v2 | ||
name: Install pnpm | ||
with: | ||
version: 8 | ||
run_install: false | ||
- name: Install | ||
run: pnpm install | ||
- name: Build | ||
run: pnpm build | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v1 | ||
with: | ||
path: demos | ||
- name: Deploy | ||
id: deployment | ||
uses: actions/deploy-pages@v1 |
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,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2023 N4NO.com | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,19 @@ | ||
# Mini Canvas Editor | ||
|
||
Canvas editor component for JavaScript application. Works with any front-end framework. Easy to integrate and use. Well-known graphical interface. Edit images, draw shapes, add texts and more. Gzipped size less than 60 KB. Uses Fabric.js internally. | ||
|
||
Main use cases: | ||
|
||
* resize image, | ||
* crop image, | ||
* create a template, render it on the front-end and the back-end (Node.js only), | ||
* create inpainting mask. | ||
|
||
Online Examples: | ||
|
||
* [🎨 Inpainting Mask](demos/webpack-app/public/inpainting-mask.html) | ||
* [🎬 Template Creator](demos/webpack-app/public/template-creator.html) | ||
|
||
## 💡 License | ||
|
||
This project is released under the MIT license. |
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,7 @@ | ||
# Mini Canvas | ||
|
||
This package contains the core features for [Mini Canvas Editor](https://github.com/b4rtaz/mini-canvas-editor). | ||
|
||
## 💡 License | ||
|
||
This project is released under the MIT license. |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,47 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>🎨 Inpainting Mask - 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" /> | ||
<style> | ||
html, | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
font: 14px/1.5em Arial, Verdana, sans-serif; | ||
min-height: 100%; | ||
background: url('./assets//background-pattern.svg'); | ||
} | ||
#placeholder { | ||
width: 100%; | ||
height: 50vh; | ||
} | ||
p, .debug { | ||
text-align: center; | ||
margin: 0; | ||
padding: 10px 0; | ||
} | ||
.preview-image { | ||
margin: 0 10px; | ||
width: 30vw; | ||
height: auto; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.15); | ||
} | ||
</style> | ||
<script src="./builds/inpainting-mask.js" defer></script> | ||
</head> | ||
<body> | ||
<div id="placeholder"></div> | ||
|
||
<div class="debug"> | ||
<img id="previewImage" class="preview-image" /> | ||
<img id="previewMaskImage" class="preview-image" /> | ||
</div> | ||
|
||
<p> | ||
<a href="">Mini Canvas Editor</a> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { Editor, EditorMode } from 'mini-canvas-editor'; | ||
import { MceImage } from 'mini-canvas'; | ||
|
||
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('placeholder') as HTMLElement; | ||
const previewImage = document.getElementById('previewImage') as HTMLImageElement; | ||
const previewMaskImage = document.getElementById('previewMaskImage') as HTMLImageElement; | ||
|
||
const editor = Editor.createFromImage(placeholder, image, false, { | ||
initialMode: EditorMode.brush, | ||
brush: { | ||
brushColor: '#ff0000', | ||
brushSize: 20 | ||
}, | ||
rect: { | ||
fillColor: '#ff0000' | ||
}, | ||
image: false, | ||
textbox: false | ||
}); | ||
const app = new App(editor, previewImage, previewMaskImage); | ||
editor.onChanged.subscribe(app.reloadPreview); | ||
app.reloadPreview(); | ||
return app; | ||
} | ||
|
||
private constructor( | ||
private readonly editor: Editor, | ||
private readonly previewImage: HTMLImageElement, | ||
private readonly previewMaskImage: HTMLImageElement | ||
) {} | ||
|
||
private readonly reloadPreview = async () => { | ||
const objects = this.editor.getWorkspaceObjects(); | ||
const image = objects.find(o => o instanceof MceImage) as MceImage; | ||
if (!image || !image.visible) { | ||
this.previewImage.src = ''; | ||
this.previewMaskImage.src = ''; | ||
return; | ||
} | ||
|
||
const [maskCanvas, maskCanvasContext] = createMemoryCanvas(this.editor.getWidth(), this.editor.getHeight()); | ||
objects.forEach(obj => { | ||
if (obj !== image) { | ||
obj.render(maskCanvasContext); | ||
} | ||
}); | ||
|
||
const [imageCanvas, imageCanvasContext] = createMemoryCanvas(this.editor.getWidth(), this.editor.getHeight()); | ||
image.render(imageCanvasContext); | ||
|
||
applyMask(this.editor.getWidth(), this.editor.getHeight(), imageCanvasContext, maskCanvasContext); | ||
|
||
this.previewImage.src = imageCanvas.toDataURL(); | ||
this.previewMaskImage.src = maskCanvas.toDataURL(); | ||
}; | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', App.preload, false); | ||
|
||
function createMemoryCanvas(width: number, height: number): [HTMLCanvasElement, CanvasRenderingContext2D] { | ||
const canvas = document.createElement('canvas'); | ||
canvas.width = width; | ||
canvas.height = height; | ||
const canvasContext = canvas.getContext('2d') as CanvasRenderingContext2D; | ||
canvasContext.fillStyle = '#ffffff00'; | ||
canvasContext.fillRect(0, 0, width, height); | ||
return [canvas, canvasContext]; | ||
} | ||
|
||
function applyMask(width: number, height: number, target: CanvasRenderingContext2D, mask: CanvasRenderingContext2D) { | ||
const imageCanvasData = target.getImageData(0, 0, width, height); | ||
const maskCanvasData = mask.getImageData(0, 0, width, height); | ||
for (let i = 0; i < imageCanvasData.data.length; i += 4) { | ||
imageCanvasData.data[i + 3] = 255 - maskCanvasData.data[i + 3]; | ||
} | ||
target.putImageData(imageCanvasData, 0, 0); | ||
} |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
/lib | ||
LICENSE | ||
README.md |
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.