Skip to content

A super useful function for applying a background colour to a canvas element before invoking toDataURL.

License

Notifications You must be signed in to change notification settings

Wildhoney/Canvas-Background

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Canvas Background

A super useful function for applying a background colour to a canvas element before invoking toDataURL.

Note: Pilfered from Mick Chambers.
Note: Likely doesn't deserve its own npm package.

npm: npm i canvas-background --save

Getting Started

Use canvas-background to apply a background colour to the canvas element before exporting it via toDataURL.

import toDataURL from 'canvas-background';

const canvas = document.querySelector('canvas');
const data = toDataURL(canvas, '#ffffff', {
    type: 'image/jpeg',
    encoderOptions: 1.0
})

Thanks to mickchambers.com.

About

A super useful function for applying a background colour to a canvas element before invoking toDataURL.

Resources

License

Stars

Watchers

Forks

Packages

No packages published