npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tinted-bitmap

v0.1.4

Published

creates a tinted copy of a given HTML image

Downloads

20

Readme

tinted-bitmap

creates a tinted copy of a given HTML Image

NPM users: please consider the Github README for the latest description of this package (as updating the docs would otherwise always require a new NPM package version)

Installation

tinted-bitmap may be used as an ECMAScript module (ESM), a CommonJS or AMD module or from a global variable.

You may either install the package into your build environment using NPM with the command

npm install tinted-bitmap

or load the plain script file directly (Browsers automatically get the bundled version, thus, the module's dependency javascript-interface-library does not have to be loaded separately)

<script src="https://unpkg.com/tinted-bitmap"></script>

Access

How to access the package depends on the type of module you prefer

  • ESM (or Svelte): import { tintedBitmap, tintedBitmapAsURL } from 'tinted-bitmap'
  • CommonJS: const tintedBitmap = require('tinted-bitmap')
  • AMD: require(['tinted-bitmap'], (tintedBitmap) => {...})

Alternatively, you may access the global variable tintedBitmap directly.

Note for ECMAScript module users: all module functions and values are exported individually, thus allowing your bundler to perform some "tree-shaking" in order to include actually used functions or values (together with their dependencies) only.

Usage within Svelte

For Svelte it is recommended to import the package within a module context:

<script context="module">
  import { tintedBitmapAsURL } from 'tinted-bitmap'
</script>

<script>
  let originalImage, tintedImageURL

  function tintOriginalImage () {
    tintedImageURL = tintedBitmapAsURL(originalImage,'limegreen')
  }

  $: if (originalImage != null) {
    if (originalImage.complete) {
      tintOriginalImage()
    } else {
      originalImage.addEventListener('load', tintOriginalImage)
    }
  }
</script>

<img bind:this={originalImage} style="vertical-align:middle" alt="original" src="..."/>
&nbsp; ➔ &nbsp;
<img style="vertical-align:middle" src={tintedImageURL} alt="tinted"/>

You will find this example in a Svelte REPL - feel free to play with it!

Usage as ECMAscript Module

If you prefer ESMs, you will presumably also use a bundler (such as rollup or webpack) to resolve any transitive dependencies and perform some "tree-shaking" to eliminate unnecessary parts (tinted-bitmap is fully tree-shakable). In this case, just import what you need and use it - your bundler will do the rest:

<script>
  import { tintedBitmapAsURL } from 'tinted-bitmap'

  window.onload = function () {
    let originalImage = document.getElementById('originalImage')
    let tintedImage   = document.getElementById('tintedImage')

    tintedImage.src = tintedBitmapAsURL(originalImage,'limegreen')
  }
</script>
<body>
  <img id="originalImage" style="vertical-align:middle" src="..."/>
  <img id="tintedImage"   style="vertical-align:middle"/>
</body>

Usage as CommonJS or AMD Module (or as a global Variable)

Let's assume that you already "required" or "imported" (or simply loaded) the module according to your local environment. In that case, you may use it as follows:

<script>
  const { tintedBitmapAsURL } = tintedBitmap

  window.onload = function () {
    let originalImage = document.getElementById('originalImage')
    let tintedImage   = document.getElementById('tintedImage')

    tintedImage.src = tintedBitmapAsURL(originalImage,'limegreen')
  }
</script>
<body>
  <img id="originalImage" style="vertical-align:middle" src="..."/>
  <img id="tintedImage"   style="vertical-align:middle"/>
</body>

Example

An example is available on the Svelte REPL - feel free to play with it!

Background Information

Sometimes it is necessary to draw a given (often b/w) raster image in a different color. tinted-bitmap performs the necessary "tinting" of such a bitmap and may construct either the data URL for the result (which is often preferred as it may be directly assigned to the src attribute of a given HTML image element) or the result itself (as an instance of HTMLImageElement)

JavaScript API

This package offers the following named JavaScript exports (function signatures are given with TypeScript type annotations, JavaScript programmers may just ignore them):

  • tintedBitmap (Bitmap:HTMLImageElement, TintColor:string):HTMLImageElement tintedBitmap takes a given HTML image element "Bitmap" (which must be complete, i.e. fully loaded), uses its alpha channel to create another image in the given TintColor (which must be a valid CSS color specification) and returns that image as an HTMLImageElement
  • tintedBitmapAsURL (Bitmap:HTMLImageElement, TintColor:string):string tintedBitmapAsURL takes a given HTML image element "Bitmap" (which must be complete, i.e. fully loaded) and uses its alpha channel to create another image in the given TintColor (which must be a valid CSS color specification). The contents of that bitmap are returned as a data URL

Build Instructions

You may easily build this package yourself.

Just install NPM according to the instructions for your platform and follow these steps:

  1. either clone this repository using git or download a ZIP archive with its contents to your disk and unpack it there
  2. open a shell and navigate to the root directory of this repository
  3. run npm install in order to install the complete build environment
  4. execute npm run build to create a new build

You may also look into the author's build-configuration-study for a general description of his build environment.

License

MIT License