Giter Club home page Giter Club logo

Comments (6)

asotog avatar asotog commented on June 22, 2024

hey @emorling, do you mean the fabric canvas instance ? from this const { selectedObjects, editor, onReady } = useFabricJSEditor() then editor.canvas.add( ... )

from fabricjs-react.

emorling avatar emorling commented on June 22, 2024

I am not sure I understand how to do this.

I understand that we can add an Image object using: editor.canvas.add( ... )

But how do we for example do this prior to adding it:

fabric.Image.fromURL('my_image.png',(oImg) => { });

from fabricjs-react.

asotog avatar asotog commented on June 22, 2024

Ah alright you are almost there, from your project you have to regular install the fabric dependency because fabricjs-react needs it as peer dependency, then you can do exactly that:

import { fabric } from 'fabric'; // this also installed on your project
import { useFabricJSEditor } from 'fabricjs-react';

const { selectedObjects, editor, onReady } = useFabricJSEditor();
fabric.Image.fromURL('my_image.png', function(oImg) { 
    editor.canvas.add( ... )
})

You can use this boilerplate we created https://codesandbox.io/s/flamboyant-wind-ff3x8

from fabricjs-react.

emorling avatar emorling commented on June 22, 2024

Fabulous! You are one of the smartest people on the planet!

BTW do you have any consulting hours this weekend, to solve this: fabricjs/fabric.js#6883

from fabricjs-react.

asotog avatar asotog commented on June 22, 2024

from fabricjs-react.

azakero avatar azakero commented on June 22, 2024

Hi. I tested the above code to render an image on the canvas, but there are multiple images being rendered. Like a million. What am I doing wrong? Here's the sandbox: https://y0rq7.csb.app/ and here's the code:

import React from "react";
import { fabric } from "fabric";
import { FabricJSCanvas, useFabricJSEditor } from "fabricjs-react";

const App = () => {
  const { selectedObjects, editor, onReady } = useFabricJSEditor();

  fabric.Image.fromURL("https://i.imgur.com/8zvUjul.jpg", function (oImg) {
    editor?.canvas.add(oImg);
  });

  return (
    <div>
      <FabricJSCanvas className="sample-canvas" onReady={onReady} />
    </div>
  );
};

export default App;

from fabricjs-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.