Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Javascript Canvas Library, SVG-to-Canvas (& canvas-to-SVG) Parser

License

NotificationsYou must be signed in to change notification settings

fabricjs/fabric.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asimple and powerful Javascript HTML5 canvas library.


🩺🧪CodeQL


cdnjsjsdelivrGitpod Ready-to-Code

NPMDownloads per monthBower


Sponsor astururSponsor melchiarSponsor ShaMan123Patreon


Features

  • Out of the box interactions such as scale, move, rotate, skew, group...
  • Built in shapes, controls, animations, image filters, gradients, patterns, brushes...
  • JPG,PNG,JSON andSVG i/o
  • Typed and modular
  • Unit tested

Supported Browsers/Environments

ContextSupported VersionNotes
Firefox✔️58
Safari✔️11
Opera✔️chromium based
Chrome✔️64
Edge✔️chromium based
Edge Legacy
IE11
Node.js✔️Node.js installation

Fabric.js does not use polyfills by default, or tries to keep it at minimum. the browser version we support is determined by the level of canvas api we want to use and some js syntax. While JS can be easily transpiled, canvas API can't.

Installation

$ npm install fabric --save# or use yarn$ yarn add fabric# or use pnpm$ pnpm install fabric

Browser

cdnjsjsdelivr

Seebrowser modules for using es6 imports in the browser or use a dedicated bundler.

Node.js

Fabric.js depends onnode-canvas for a canvas implementation (HTMLCanvasElement replacement) andjsdom for awindow implementation on node.This means that you may encounternode-canvas limitations andbugs.

Follow theseinstructions to getnode-canvas up and running.

Quick Start

// v6import{Canvas,Rect}from'fabric';// browserimport{StaticCanvas,Rect}from'fabric/node';// node// v5import{fabric}from'fabric';
Plain HTML
<canvasid="canvas"width="300"height="300"></canvas><scriptsrc="https://cdn.jsdelivr.net/npm/fabric@6.4.3/dist/index.js"></script><script>constcanvas=newfabric.Canvas('canvas');constrect=newfabric.Rect({top:100,left:100,width:60,height:70,fill:'red',});canvas.add(rect);</script>
React.js
importReact,{useEffect,useRef}from'react';import*asfabricfrom'fabric';// v6import{fabric}from'fabric';// v5exportconstFabricJSCanvas=()=>{constcanvasEl=useRef<HTMLCanvasElement>(null);useEffect(()=>{constoptions={ ...};constcanvas=newfabric.Canvas(canvasEl.current,options);// make the fabric.Canvas instance available to your appupdateCanvasContext(canvas);return()=>{updateCanvasContext(null);canvas.dispose();}},[]);return<canvaswidth="300"height="300"ref={canvasEl}/>;};
Node.js
importhttpfrom'http';import*asfabricfrom'fabric/node';// v6import{fabric}from'fabric';// v5constport=8080;http.createServer((req,res)=>{constcanvas=newfabric.Canvas(null,{width:100,height:100});constrect=newfabric.Rect({width:20,height:50,fill:'#ff0000'});consttext=newfabric.Text('fabric.js',{fill:'blue',fontSize:24});canvas.add(rect,text);canvas.renderAll();if(req.url==='/download'){res.setHeader('Content-Type','image/png');res.setHeader('Content-Disposition','attachment; filename="fabric.png"');canvas.createPNGStream().pipe(res);}elseif(req.url==='/view'){canvas.createPNGStream().pipe(res);}else{constimageData=canvas.toDataURL();res.writeHead(200,'',{'Content-Type':'text/html'});res.write(`<img src="${imageData}" />`);res.end();}}).listen(port,(err)=>{if(err)throwerr;console.log(`> Ready on http://localhost:${port}, http://localhost:${port}/view, http://localhost:${port}/download`,);});

See our ready to usetemplates.


Other Solutions

ProjectDescription
Three.js3D graphics
PixiJSWebGL renderer
KonvaSimilar features
html-to-imageHTML to image/canvas

More Resources

CreditsPatreon

About

Javascript Canvas Library, SVG-to-Canvas (& canvas-to-SVG) Parser

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp