
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
image-shader
Advanced tools
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 );
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.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.dispose()
Releases all memory. Since it uses WebGL internally, simply losing the reference will not clear
all memory.FAQs
Run WebGL shaders on an image or canvas.
The npm package image-shader receives a total of 1 weekly downloads. As such, image-shader popularity was classified as not popular.
We found that image-shader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.