Comments (6)
Minipaint is all client code. A bunch of js, css, and html file. It doesn't really matter, the only real requirement is that it is served from the same domain that your react code is running on, so the Javascript can communicate across the boundaries of the iframe.
from minipaint.
This is an example of loading and saving images https://github.com/viliusle/miniPaint/blob/master/examples/open-edit-save.html
For React specifically, you can add a ref to the iframe element to retrieve it if you don't want to use the id.
import { useRef, useEffect } from 'react';
export default function ModalEditTemplate() {
const minipaintIframe = useRef(null);
const isMinipaintIframeLoaded = useRef(false);
useEffect(() => {
if (minipaintIframe.current && isMinipaintIframeLoaded.current) {
// When the iframe ref is populated from the component template,
// call API to load image...
const Layers = minipaintIframe.current.contentWindow.Layers;
const newLayer = {
// Reference example I linked above
};
Layers.insert(newLayer);
}
}, []);
function onMinipaintIframeLoad() {
isMinipaintIframeLoaded.current = true;
}
return (
<iframe
ref={minipaintIframe}
style={{ width: "70vw", height: "70vh" }}
src={`https://YOURWEBSITE.COM/miniPaint/`}
allow="camera"
onLoad={onMinipaintIframeLoad}
></iframe>
);
}
I haven't tested this code, but theoretically it should work. You need to wait for both the ref for the iframe element to be assigned, and for the iframe to load the minipaint page.
from minipaint.
Also, I didn't notice this at first, but you'll need to self-host minipaint on your own server, not reference it from https://viliusle.github.io/.
Javascript won't talk across iframes on different domains.
from minipaint.
Also, I didn't notice this at first, but you'll need to self-host minipaint on your own server, not reference it from https://viliusle.github.io/.
Javascript won't talk across iframes on different domains.
Thank you very much for your previous response, it has been very helpful to me.
One more question, I have my project separated into client with react and server with strapi (node.js). I have the client hosted on netlify, and the server on railway.
Where should I host mini paint? On railway or on netlify?
from minipaint.
@viliusle may want to consider adding a postMessage API so people can do basic things like load and save images from viliusle.github.io/miniPaint/ without having to self-host.
from minipaint.
from minipaint.
Related Issues (20)
- Pan HOT 3
- Brush size isn't remembered on page refresh HOT 2
- Reversing the Persian text HOT 1
- Default color value HOT 2
- Drawing on a Single Layer HOT 2
- Auto Convert to Raster HOT 1
- Custom Pencils and Erasers
- Exe for local use? HOT 3
- Is there any way or option to hide and show the sidebar_right? HOT 2
- Customize language HOT 4
- [Feature Request] Crop layer HOT 2
- 运用miniPaint搭建了一套中文版在线ps网页,为什么有的单词翻译的不准确,比如guide HOT 5
- Feature Request HOT 3
- The picture is not visible HOT 10
- Change the Default Setting of transparent to On HOT 6
- IME input compatible HOT 6
- Sending images to my miniPaint instance from the URL HOT 4
- docker hub HOT 1
- Moving of assets HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minipaint.