Scrawl-canvas VS fabric.js

Compare Scrawl-canvas vs fabric.js and see what are their differences.

Scrawl-canvas

Responsive, interactive and more accessible HTML5 canvas elements. Scrawl-canvas is a JavaScript library designed to make using the HTML5 canvas element easier, and more fun (by KaliedaRik)

fabric.js

Javascript Canvas Library, SVG-to-Canvas (& canvas-to-SVG) Parser (by fabricjs)
Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
Scrawl-canvas fabric.js
37 49
306 27,419
- 1.4%
8.8 9.3
5 days ago 6 days ago
JavaScript JavaScript
GNU General Public License v3.0 or later GNU General Public License v3.0 or later
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

Scrawl-canvas

Posts with mentions or reviews of Scrawl-canvas. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2024-03-21.
  • Show HN: Dropflow, a CSS layout engine for node or <canvas>
    15 projects | news.ycombinator.com | 21 Mar 2024
    > working with glyphs and iterating them in reverse for RTL is brain-breaking. And line wrapping gets really complicated. It's also the most obscure because nobody has written down everything you need to know in one place

    I can confirm this. I've been working on a (much simpler!) text layout engine for my canvas library over the past couple of months and the amount of complexity associated with just stamping some glyphs onto a canvas has left me screaming at my laptop on an almost daily basis. Getting a decent underline was a proud moment!

    Question: did you ever find out what algorithm the various browsers are using to calculate how many words can fit on a given line? I'm almost there, except words will occasionally jump between lines when I scale the text. Really annoying!

    The PR's still a work in progress, but I've got all the functionality I want in there (shaping lines to fit in non-rectangular containers, styling text, text along a non-straight line, dynamic updates, etc). Just need to test and document it all now ... https://github.com/KaliedaRik/Scrawl-canvas/pull/75

  • Ask HN: What are you working on this year?
    1 project | news.ycombinator.com | 1 Jan 2024
    I've got myself organised and prepared a List Of Things To Do[1] to make my 2D Javascript library even better than it already is. Given that I've been working on the library for over 10 years now, and have never before set out such a list, I call this Progress!

    [1] https://github.com/KaliedaRik/Scrawl-canvas/discussions/cate...

  • Pixelating Live with SVG
    1 project | news.ycombinator.com | 24 Dec 2023
    'Kay, I don't know if this anywhere close to what the OP wants, but this sort of live browser tab manipulation is possible to do using a mix of a a canvas element and the browser's Screen Capture API[1] (plus my JS canvas library, once I merge and publish the changes into its next release[2]).

    This solution[3] shows the modified browser tab in a separate browser tab. I've got no idea whether it's possible to do the same sort of trick in the same tab (but probably not). I also have no idea how secure the Screen Capture API is - I'd get very nervous about doing this sort of thing when looking at my bank's online portal!

    [1] https://developer.mozilla.org/en-US/docs/Web/API/Screen_Capt...

    [2] https://github.com/KaliedaRik/Scrawl-canvas/pull/57

    [3] Youtube video of the effect: https://www.youtube.com/watch?v=hCi6LmKMAo0

  • Scrawl-canvas 2D canvas library – proposed roadmap
    1 project | news.ycombinator.com | 28 May 2023
  • Scrawl-canvas - a Javascript library for working with the HTML5 &lt;canvas&gt; element
    1 project | /r/javascript | 2 Mar 2023
  • Motion Canvas – Visualize complex ideas programmatically
    5 projects | news.ycombinator.com | 22 Feb 2023
    My canvas library's README[1] has a video embedded in it. FWIW I'm not convinced it adds anything to the library's sales pitch.

    [1] https://github.com/KaliedaRik/Scrawl-canvas

  • Egui commit: Implement accessibility APIs via AccessKit
    5 projects | news.ycombinator.com | 4 Dec 2022
    > And I’m just mentioning some of the unfixable problems with this approach

    I agree that using a canvas instead of leveraging existing accessibility supplied by HTML/CSS/JS and the DOM is an accessibility nightmare.

    However, I disagree that canvas accessibility issues are "unfixable". Difficult? Yes. But not unfixable. In my view, the element works best in partnership with its wider environment (HTML/CSS/JS and the DOM), not as a replacement for it. With that in mind, we can start to tackle the accessibility issues you raise - fonts, links, interactions, etc.[1][2]

    I have an ambition to one day become intelligent enough to understand/code in Rust, and I'm really glad to see that people are thinking about accessibility as a fundamental part of UIs being developed in Rust.

    [1] - Which is what my JS 2d canvas library tries to do: https://scrawl-v8.rikweb.org.uk/

    [2] - My thoughts on accessibility, and how I try to fix them using my library: https://scrawl-v8.rikweb.org.uk/learn/eleventh-lesson/

  • [AskJS] Why do my coworkers not see the value in frameworks?
    2 projects | /r/javascript | 15 Nov 2022
    If, however, your company is set on this course, I very strongly suggest you use a canvas library - if only for the MVP. Here's my canvas library (spam alert!) ... even if you don't use it in your product, the library might help give you some ideas on how to overcome some of the responsive, interactive and accessibility issues you'll be facing.
  • which technology or framework is used to create geometry-draggable canvas like this?
    7 projects | /r/Frontend | 23 Oct 2022
    Scrawl-canvas - example and another example (links to code at bottom of each page)
  • TypeScript is terrible for library developers
    16 projects | news.ycombinator.com | 23 Aug 2022
    My personal experience as a library developer, who has written my library in JS, not TS ...

    TS is an excellent choice for a lib dev starting a new project today. I can see the advantages of using TS for the library code - in particular for a library that gets popular and welcomes contributions from other developers. However TS is a nightmare for someone like me who: 1. started writing the library 9 years ago; 2. has let the library get "quite" big; and 3. has only learned to use TS in the past year (for the day job) and is nowhere near to becoming a types expert.

    I've had experience of people suggesting I rewrite the library in TS. Sometimes those suggestions have been quite 'evangelical' in their tone. As an (essentially) solo developer I just don't have the time, capacity or willingness to do that work - however much the end results might please others.

    I also understand that having type definitions file for the library's interface is, nowadays, a critical factor if the lib dev wants others to use the library in their projects. But writing a .d.ts file for a large, mature repo to at least help those potential users can quickly turn into a World of Hurt. I know this because I've done that work[1] and I never want to do it again.

    As much as I know that TS is a Force for Good in the JS coding world, there are days when I detest it!

    [1] - link to the Scrawl-canvas .d.ts file on GitHub - https://github.com/KaliedaRik/Scrawl-canvas/blob/master/sour...

fabric.js

Posts with mentions or reviews of fabric.js. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2024-04-12.
  • Fun, Beautiful, Printable 'Story Cards' for Kids with Cloudflare AI
    3 projects | dev.to | 12 Apr 2024
    This AI-powered Story Card Maker is built as a SvelteKit application with Typescript. Using Flowbite Svelte component library, the whole application was laid out. The layout for the Story Card (emulating the size of a postcard - 4" x 3") is created as an HTML Canvas using Fabric.js.
  • JSON Canvas – An open file format for infinite canvas data
    12 projects | news.ycombinator.com | 11 Mar 2024
  • Step by step on how to setup fabric.js in the next.js app
    1 project | dev.to | 30 Sep 2023
    Fabric.js is a powerful and simple Javascript HTML5 canvas library. It provides an interactive object model on top of the canvas element. Fabric also has SVG-to-canvas (and canvas-to-SVG) parser.
  • How I choose Fabric.js again
    2 projects | dev.to | 3 Sep 2023
    Based on this, I found that some of the libraries are dead and no longer have any support. Only two libraries are still alive and have significant amount of stars on GitHub and downloads on NPM. They are Fabric.js and Konva.js.
  • Building application Like Canva in ReactJS
    1 project | /r/react | 29 Jun 2023
    I'm actually in the process of building something similar. It's a React app and I'm using the FabricJs library
  • How can I build a configurator like this ?
    1 project | /r/react | 10 May 2023
    I've played with this tech in early 2010s - they are using HTML5 Canvas tech + something like Fabric.js(http://fabricjs.com/) that controls Canvas objects.
  • Canvas Element with multiple images that can be moved?
    1 project | /r/webdev | 19 Apr 2023
    this library might help you: http://fabricjs.com/
  • How would I wrap an image on an object in web?
    1 project | /r/webdev | 14 Mar 2023
    I did some research and the most promising result was using Fabric.js (http://fabricjs.com/) to put images on products. I may not be experienced enough in JS to understand the full capabilities of this library, but it looks like most of their stuff works on flat surfaces. I am trying to replicate the properly wrapped/textured affect that is achieved in the blanket below.
  • Any ideas on how to build this floating sidebar and how it functions?
    1 project | /r/webdev | 10 Mar 2023
    set up a canvas drawing & rendering framework, for example http://fabricjs.com/
  • Image Manipulation with Fabric.js and Canvas
    1 project | dev.to | 29 Nov 2022
    body{ display:flex; flex-direction:column; align-items:center; }

    Learning Fabric

    Enter fullscreen mode Exit fullscreen mode

    Next, we initiate a Canvas instance in our script tag:

    Syntax

    new fabric.Canvas(element: HTMLElement|String, options: Object)
    
    Enter fullscreen mode Exit fullscreen mode

    This allows Fabric.js to create this class instance so that we can use the provided methods of Fabric.js:

    const canvas = new fabric.Canvas("canvas", {})
    
    Enter fullscreen mode Exit fullscreen mode

    Now, we’ll go ahead and give our canvas different properties, such as width, height, and background color:

    const canvas = new fabric.Canvas("canvas", {
     width:500,
     height:500,
     backgroundColor:green
    })
    
    Enter fullscreen mode Exit fullscreen mode

    Output

    Creating a Rectangle with Fabric.js

    Now that we’ve initialized a canvas and given it various properties, we’re going to create a rectangle using the Fabric.js object fabric.Rect:

    Syntax

    new fabric.Rect({object})
    
    Enter fullscreen mode Exit fullscreen mode

    Here the object houses the rectangle properties:

    const canvas = new fabric.Canvas("canvas", {
     width:500,
     height:500,
     backgroundColor:green
    });
    
    const rectangle = new fabric.Rect({
     width:200,
     height:200,
     /* fill is used to define the background color*/
        fill:'red'
    })
    /*the add method is used to add objects to the canvas element */
    canvas.add(rectangle)
    /*the renderAll method used to render the canvas*/
    canvas.renderAll();
    
    Enter fullscreen mode Exit fullscreen mode

    The add() method is used to add objects to the Canvas element. In this case, it adds the rectangle we created to the canvas:

    Output

    Creating a Circle

    In the same way, we’ll create a circle. This time, we’ll use fabric.Circle:

    const canvas = new fabric.Canvas("canvas", {
     width:500,
     height:500,
     backgroundColor:"lightgray"
    });
    
    const circle = new fabric.Circle({
     radius:60,
     fill:"blue"
    })
    canvas.add(circle);
    canvas.renderALl();
    
    Enter fullscreen mode Exit fullscreen mode

    Output

    With the above steps, we created a rectangle and a circle using Fabric.js. Note how interactive the objects are! Next, we’ll discuss images in Fabric.js.

    Images with Fabric

    The Fabric.Image is a Fabric.js object used to render images on a canvas. With Fabric.js, we can interact with the image. Images can be added to our canvas in two ways:

    • Fabric.Image
    • Fabric.Image.fromURL

    Using the Fabric.Image constructor requires us to create an image element in our HTML and then insert it into the constructor:

    Syntax

    fabric.Image(image_element)
    
    Enter fullscreen mode Exit fullscreen mode

    HTML

    
    
    
    
    Enter fullscreen mode Exit fullscreen mode

    JS

    const image_element = document.querySelector('#image');
    const image = new fabric.Image(image_element)
    canvas.add(image);
    canvas.renderAll();
    
    Enter fullscreen mode Exit fullscreen mode

    However, Fabric.Image.fromURL requires only the image URL (the URL can be retrieved from a website or your local folder), and is simpler than the former:

    fabric.Image.fromURL(URL, function());
    
    Enter fullscreen mode Exit fullscreen mode

    After passing the URL, the callback function after the image is loaded. The first default parameter of the callback function is the fabric.Image object. Now, we can modify the image properties and then add it to the canvas:

    const canvas = new fabric.Canvas("canvas", {
     width:500,
     height:500,
     backgroundColor:"White"
    });
    
    fabric.Image.fromURL('my_image.png',(img) => {
     // the scaleToHeight property is use to set the image height
        img.scaleToHeight(250)
     // scaleToWidth is use to set the image width
        img.scaleToWidth(250)
        canvas.add(img)  
    })
    canvas.renderAll()
    
    Enter fullscreen mode Exit fullscreen mode

    Output

    Editing Images with Fabric.js

    Now that we know how to insert an image into a canvas, we’ll look at other image objects like image filters.

    Image Filters

    Fabric.js provides us with built-in filters:

    • BaseFilter
    • Brightness
    • convolute
    • GradientTransparency
    • Grayscale
    • Invert
    • Mask
    • Noise
    • Pixelate
    • RemoveWhite
    • Sepia
    • Sepia2
    • Tint

    Every instance of fabric.Image has the "filters" property, which is a simple array of filters. We can use the array method to perform any required operation, including removing filters (pop, slice, shift), adding filters (push, unshift, slice), and even combining multiple filters. When we call applyFilters, any filter in the “filters” array will be applied one by one. Let’s use some of these filters:

    Syntax

    new fabric.Image.filters
    // after that you can add any filter of your choice
    // Example 
    new fabric.Image.filters.Grayscale()
    
    Enter fullscreen mode Exit fullscreen mode
    fabric.Image.fromURL('my_image.png', (image) => {
          image.scaleToHeight(300)
           image.ScaleToWidth(300)
    
     // Creating filter
     const filter = new fabric.Image.filters.Grayscale()
    
     //push the filter instance to filters
            image.filter.push(filter)
    
     // apply filter
             image.applyFilters()
    
     //add image into canvas (it also re-render the canvas)
             canvas.add(image)
    },{crossOrigin: 'anonymous'});
    canvas.renderAll();
    
    Enter fullscreen mode Exit fullscreen mode

    Output

    Above, we used the Grayscale filter; we can also apply other filters. All we have to do is simply change the filter, as shown in this example:

    fabric.Image.fromURL('my_image.png', (image) => {
          image.scaleToHeight(300)
           image.ScaleToWidth(300)
    
     // creating filter
     const filter = new fabric.Image.filters.Sepia()
    
     //add filter
            image.filter.push(filter)
    
     // apply filter
             image.applyFilters()
    
     //add image into canvas (it also re-render the canvas)
             canvas.add(image)
    },{crossOrigin: 'anonymous'});
    canvas.renderAll();
    
    Enter fullscreen mode Exit fullscreen mode

    Output

    Image Blending

    Blending is mixing two or more images to create a new image. Fabric.js gives us this ability. Here, we’re going to use the image blending filter for our image:

    Syntax

    new fabric.Image.filters.BlendImage({
     // the image that we want to blend
              image:imageA,
     // blend mode (in this case we are using the 'add' mode)
              mode:'add',
    
     alpha:0.5
          });
    
    Enter fullscreen mode Exit fullscreen mode
    fabric.Image.fromURL('my_image.png', (imageA) => {
        imageA.scaleToWidth(350)
        imageA.scaleToHeight(350)
        canvas.add(imageA)
    
     // Blending filter
        filter = new fabric.Image.filters.BlendImage({
     image:imageA,
     mode:'add',
     alpha:0.5
          });
    
     //Add the second image  
         fabric.Image.fromURL('my_image2.png',(imageB) => {
               imageB.scaleToHeight(100),
                imageB.scaleToWidth(100),
                canvas.add(imageB)
           }, {crossOrigin:''});
    
         imageA.filters.push(filter);
         imageA.applyFilters(canvas.renderAll.bind(canvas));
    },{crossOrigin:''})
    
    Enter fullscreen mode Exit fullscreen mode

    Output

    Image Clipping

    A very popular effect used today is image clipping, or rather image cropping, which is done to remove parts of an image that we don’t want. With Fabric.js, we can achieve this by using the clipPath method.

    First, we have to create our own clipPath using any Fabric.js object. Then, we’ll assign it to the clipPath property of the object we want to clip. Here, we’ll use a circle object:

    const clipPath = new fabric.Circle({
     radius:150,
     top:200,
     left:250,
     // The originY and originX helps to center the image and the clipPath
        originY:"center",
     originX:"center"
    })
    
    Enter fullscreen mode Exit fullscreen mode

    After that, we add it to the image that we want to clip using the filter method:

    new fabric.Image.fromURL('my_image.png',(img) => {
      img.scaleToHeight(300)
      img.scaleToWidth(300)
     // positioning the image
      img.scale(o.5).set({top:50,left:100})
     // Clip Path
      clipPath = new fabric.Circle({
     radius:150,
     top:200,
     left:250,
     originY:"center",
     originX:"center"
        })
      canvas.add(img)
      canvas.clipPath = clipPath;
      });
    canvas.renderAll();
    
    Enter fullscreen mode Exit fullscreen mode

    Output

    Image Blurring

    Like other image filters, the blur filter accepts objects because they can be adjusted. A practical example is changing the brightness of an image. You can apply other image filters without any additional configurations (like grayscale, invert, or sepia). Other image filters like brightness, pixelate, tint, and noise all operate in this way, too. However, the difference is that their values are not the same. The brightness filter's actual brightness level ranges from-1 (full black) to 1 (full white). The noise filter's value is between 0 and 1000. For the blur filter, the value ranges from 0 to 10.

    Syntax

    new fabric.Image.filters.Blur(object)
    
    Enter fullscreen mode Exit fullscreen mode
    fabric.Image.fromURL('my_image.png', (image) => {
          image.scaleToHeight(300)
           image.ScaleToWidth(300)
    
     // Creating the blur filter
     const filter = new fabric.Image.filters.Blur({
     blur:0.6
           })
    
     //push the filter instance to filters
            image.filter.push(filter)
             image.applyFilters()
             canvas.add(image)
    },{crossOrigin: 'anonymous'});
    canvas.renderAll();
    
    Enter fullscreen mode Exit fullscreen mode

    Output

    Conclusion

    In conclusion, Fabric.js gives us an awesome experience when working with Canvas. It also provides a lot of features, some of which we covered in this article. For full details on some of the Fabric.js objects, you can review its documentation here.

What are some alternatives?

When comparing Scrawl-canvas and fabric.js you can also consider the following projects:

tsParticles - tsParticles - Easily create highly customizable JavaScript particles effects, confetti explosions and fireworks animations and use them as animated backgrounds for your website. Ready to use components available for React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Solid, Riot and Web Components.

paper.js - The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey

particles-bg - React particles animation background component

p5.js - p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —

Mo.js - The motion graphics toolbelt for the web

Konva - Konva.js is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.

particles.js - A lightweight JavaScript library for creating particles

three.js - JavaScript 3D Library.

GreenSock-JS - GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web

d3 - Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:

barba - Create badass, fluid and smooth transitions between your website’s pages

GoJS, a JavaScript Library for HTML Diagrams - JavaScript diagramming library for interactive flowcharts, org charts, design tools, planning tools, visual languages.