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

image-shader

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-shader

Run WebGL shaders on an image or canvas.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Shader Image

experimental

Tool to simplify writing shaders for HTML Image and Canvas elements.

This class class creates a webgl context and texture from a given HTMLImageElement or HTMLCanvasElement as well as a fragment shader.

The shader is wrapped with the necessery definitions and functions to render the image.

import { ShaderImage } from "shader-image";

const source = new Image();
source.src = "some/url.png";

// only render the red channel of the image.
const shader = `
    void main() {
        vec4 pixel = getImagePixel();

        gl_FragColor = vec4( pixel.r, 0, 0, 1 );
    }
`;

const image = new ShaderImage( source, shader );

document.body.appendChild( image.domElement );

Api

new ShaderImage( source, shader ) where source is either a HTMLImageElement or a HTMLCanvasElement and the shader is a string in form of webgl shader. This means it has to include a void main() method in which or subsequently from which the gl_FragColor is set.

Within the shader, these extra values are accessable:

  • vec4 getImagePixel(): Returns a vec4 of the current pixel in the fragment.
  • vec2 uv: The UV Coordinates of the current pixel.

Fields

  • domElement Returns a HTMLCanvasElement in the size of the source image containing the shaded image.
  • width Returns the width of the content.
  • height Returns the height of the content.

Methods

  • dispose() Releases all memory. Since it uses WebGL internally, simply losing the reference will not clear all memory.

Keywords

FAQs

Package last updated on 17 May 2018

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