New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

auto-canvas

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auto-canvas

Make canvas adapted to retina(HD) display

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

auto-canvas

Get canvas context which adapted to retina(HD) display

Installation

npm install auto-canvas

Example

  1. In your HTML file, put the canvas inside a wrapper and give it an id for later use. Let's assume we put it in a <div>. The canvas will be scaled 100% size of its parent node
<div class="canvas-wrapper">
  <canvas id="canvas-id"></canvas>
</div>
  1. In your JS file
import autoCanvas from 'auto-canvas'

const canvasNode = document.querySelector('#canvas-id')

// get 2d context
// const ctx = autoCanvas(canvasNode, '2d')

// get webgl context
// const ctx = autoCanvas(canvasNode, 'webgl')

// auto scale canvas, no context returned, have to get it manually
autoCanvas(canvasNode)

/**
 * the canvas's width and height attr has been modified inside * `autoCanvas`
 * so this line must be after `autoCanvas` is called
 */
const WIDTH = canvasNode.width // scaled width
const HEIGHT = canvasNode.height // scaled height

// do whatever you want with your canvas

API Documentations

Auto scale your canvas

autoCanvas(node, type)

where:

  • node is the canvas node
  • type is the type of context you want. This is optional, if not provided, the function returns nothing, else returns the context of the canvas

v2 to v3

  1. getAutoContext has been renamed to autoCanvas
  2. autoCanvas does not return any context except when you set the second parameter.

FAQs

Package last updated on 01 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc