Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jhildenbiddle/canvas-size
Determine the maximum area, height, width, and custom dimensions of an HTML canvas element.
https://github.com/jhildenbiddle/canvas-size
area canvas height html limit maximum offscreen offscreencanvas scale size test width worker
Last synced: 14 days ago
JSON representation
Determine the maximum area, height, width, and custom dimensions of an HTML canvas element.
- Host: GitHub
- URL: https://github.com/jhildenbiddle/canvas-size
- Owner: jhildenbiddle
- License: mit
- Created: 2018-11-29T22:07:37.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-14T04:57:26.000Z (7 months ago)
- Last Synced: 2024-04-14T13:51:27.556Z (7 months ago)
- Topics: area, canvas, height, html, limit, maximum, offscreen, offscreencanvas, scale, size, test, width, worker
- Language: JavaScript
- Homepage: https://jhildenbiddle.github.io/canvas-size/
- Size: 879 KB
- Stars: 233
- Watchers: 4
- Forks: 18
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# canvas-size
[![NPM](https://img.shields.io/npm/v/canvas-size.svg?style=flat-square)](https://www.npmjs.com/package/canvas-size)
[![GitHub Workflow Status (master)](https://img.shields.io/github/actions/workflow/status/jhildenbiddle/canvas-size/test.yml?branch=master&label=checks&style=flat-square)](https://github.com/jhildenbiddle/canvas-size/actions?query=branch%3Amaster+)
[![Codacy code quality](https://img.shields.io/codacy/grade/c39af90445e7478d80fd796d12947495/master?style=flat-square)](https://app.codacy.com/gh/jhildenbiddle/canvas-size/dashboard?branch=master)
[![Codacy branch coverage](https://img.shields.io/codacy/coverage/c39af90445e7478d80fd796d12947495/master?style=flat-square)](https://app.codacy.com/gh/jhildenbiddle/canvas-size/dashboard?branch=master)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://github.com/jhildenbiddle/canvas-size/blob/master/LICENSE)
[![jsDelivr](https://data.jsdelivr.com/v1/package/npm/canvas-size/badge)](https://www.jsdelivr.com/package/npm/canvas-size)
[![Sponsor this project](https://img.shields.io/static/v1?style=flat-square&label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/jhildenbiddle)Determine the maximum area, height, width, and custom dimensions of an HTML `` element.
- 🚀 [Documentation & Demo](https://jhildenbiddle.github.io/canvas-size/)
- 🔬 [Test Results](https://jhildenbiddle.github.io/canvas-size/#/?id=test-results)## Why?
The [HTML canvas](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas) element is [widely supported](http://caniuse.com/#feat=canvas) by modern and legacy browsers, but each browser and platform combination imposes unique size limitations (see [Test Results](https://jhildenbiddle.github.io/canvas-size/#/?id=test-results)) that will render a canvas unusable when exceeded. Unfortunately, browsers do not provide a way to determine what their limitations are, nor do they provide any kind of feedback after an unusable canvas has been created. This makes working with large canvas elements a challenge, especially for applications that support a variety of browsers and platforms.
This micro-library provides the maximum area, height, and width of an HTML canvas element supported by the browser as well as the ability to test custom canvas dimensions. By collecting this information _before_ a new canvas element is created, applications are able to reliably set canvas dimensions within the size limitations of each browser/platform.
## Features
- Determine the maximum `` area, height, and width
- Test custom `` dimensions
- Web worker + OffscreenCanvas support
- UMD and ES6 module available
- Lightweight (< 1k min+gzip) and dependency-free**Browser Support**
Chrome 24+
Edge 12+
Firefox 26+
Safari 8+
Internet Explorer 10+## Installation
**NPM**
```bash
npm install canvas-size
``````js
import canvasSize from 'canvas-size';
```**CDN**
Available on [jsdelivr](https://www.jsdelivr.com/package/npm/canvas-size) (below), [unpkg](https://unpkg.com/browse/canvas-size/), and other CDN services that auto-publish npm packages.
```html
```
```html
```
> 💡 Note the `@` version lock in the URLs above. This prevents breaking changes in future releases from affecting your project and is therefore the safest method of loading dependencies from a CDN. When a new major version is released, you will need to manually update your CDN URLs by changing the version after the `@` symbol.
## Usage & Options
See the [documentation site](https://jhildenbiddle.github.io/canvas-size/) for details.
## Sponsorship
A [sponsorship](https://github.com/sponsors/jhildenbiddle) is more than just a way to show appreciation for the open-source authors and projects we rely on; it can be the spark that ignites the next big idea, the inspiration to create something new, and the motivation to share so that others may benefit.
If you benefit from this project, please consider lending your support and encouraging future efforts by [becoming a sponsor](https://github.com/sponsors/jhildenbiddle).
Thank you! 🙏🏻
## Contact & Support
- Follow 👨🏻💻 **@jhildenbiddle** on [Twitter](https://twitter.com/jhildenbiddle) and [GitHub](https://github.com/jhildenbiddle) for announcements
- Create a 💬 [GitHub issue](https://github.com/jhildenbiddle/canvas-size/issues) for bug reports, feature requests, or questions
- Add a ⭐️ [star on GitHub](https://github.com/jhildenbiddle/canvas-size) and 🐦 [tweet](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2Fjhildenbiddle%2Fcanvas-size&hashtags=css,developers,frontend,javascript) to promote the project
- Become a 💖 [sponsor](https://github.com/sponsors/jhildenbiddle) to support the project and future efforts## License
This project is licensed under the MIT License. See the [LICENSE](https://github.com/jhildenbiddle/canvas-size/blob/master/LICENSE) for details.
Copyright (c) John Hildenbiddle ([@jhildenbiddle](https://twitter.com/jhildenbiddle))