{
  "id": 22213068,
  "title": "Add a paint bucket to an existing Fabric.js canvas",
  "url": "https://urgent.news/2026/11/27/add-a-paint-bucket-to-an-existing-fabric-js-canvas",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-27T19:07:05.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/codingdudecom/add-a-paint-bucket-to-an-existing-fabricjs-canvas-52i1"
  },
  "original_language": "en",
  "account": "To add a paint bucket feature to an existing Fabric.js canvas, start by copying the floodfill.global.js file from the repository. Load this file after the Fabric.js script, ensuring it is loaded last. Within your JavaScript code, create a new instance of the floodfill object using the fabricjs-floodfill library. Pass your existing canvas instance and the image class reference to the createFloodFill function.\n\nNext, attach an event listener to your canvas for mouse down events. In the event handler, check if the left mouse button was clicked; if not, invoke the fillFromEvent method on your floodfill instance. This method takes the event object and your desired fill color as parameters.\n\nThe floodfill algorithm identifies boundaries within the visible canvas area, including images, shapes, and strokes. Each filling operation is treated as a separate Fabric image, preserving the original editable objects. If working with outlines that have small gaps, pass the { gapClose: 4 } object as the third argument to the fillFromEvent method to improve filling accuracy.\n\nThe provided browser test matrix includes Fabric.js versions 3.4.0, 4.6.0, 5.2.1, 6.9.1, and 7.4.0. After testing in your own environment, you may wish to share your experiences, particularly with thin outlines or small gaps, as these are areas the author would like to explore further.",
  "summary": "I wanted to add a paint bucket to a Fabric.js canvas so I could click inside an outline and fill it with color. I built fabricjs-floodfill and put together a coloring demo so you can try it before adding it to your own app. Try the coloring demo · View the source on GitHub Add it to your canvas Copy floodfill.global.js from the repo. Load it after Fabric.js, then pass in your existing canvas…",
  "summary_source": "publisher",
  "key_points": [
    "Copy floodfill.global.js after Fabric.js script",
    "Create floodfill object with canvas and image class",
    "Attach mouse down event listener for fillFromEvent"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}