
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
fast-image-viewer
Advanced tools
Fast Image Viewer (FIV) allows you to Render Really big big, huge, files into a canvas and manipulate those images as if they were a Visualization tool in browser, all of this, simply embeded into any DOM Element.
FIV was mainly created to render Huge SVG files, and navigate them in a browser, at 60fps, always keeping a low (RAM/VRAM) memory footprint.
Under the hood, fast image viewer, uses WebGL. It creates a Grid of the original image and renders it into several Quads. FIV will smartly identify the size of the current device and start with a texture matching the highest dimension between the width and the height (or the closest power of two dimension). As you get closer to the Image, FIV will start subdividing the Grid into smaller pieces, while doubling the size of each Quadrant into the GRID to keep a low memory footprint, but a high resolution.
npm install fast-image-viewer
FIV provides you with the base Handler which runs the Image (PNG, PDF, SVG, etc) lifecycle. The Handler will first create a Canvas as a container used to Generate each of the GRIDS, and then call the load function which will, as defined for the implementer, load the resources into the class. Once the file has been loaded (Sync), the draw function will be called. The draw function is in charge of drawing to the Canvas the desired resources. After draw function exit, the Canvas should contain the final image that will then, be displayed into the viewer.
class SVGHandler extends FastSvgViewer.Handler {
/**
* [load description]
* @return {Promise} [description]
*/
load (BASE_URL) {
let request = new XMLHttpRequest();
let $this = this;
request.open('GET', BASE_URL, false);
request.send(null);
const documentFragment = document.createDocumentFragment();
const div = document.createElement('div');
documentFragment.appendChild(div);
div.innerHTML = request.responseText;
$this.viewBox = div
.getElementsByTagName('svg')[0]
.getAttribute('viewBox')
.split(' ')
.map(Number);
const paths = div.getElementsByTagName('path');
$this.data = [];
for (let i = 0; i < paths.length; i++) {
$this.data[i] = {
path: new Path2D(paths[i].getAttribute('d')),
fill: paths[i].getAttribute('fill')
}
}
}
/**
* [Draw imageData]
* @return {Promise}
*/
draw () {
this.context.lineWidth = 20;
this.context.strokeStyle = "#444";
for (let i = 0; i < this.data.length; i++) {
this.context.fillStyle = this.data[i].fill;
this.context.fill(this.data[i].path);
}
}
/**
* [Clear all references]
* @return {[type]} [description]
*/
clear () {
super.clear();
this.data = null;
}
}
FastSvgViewer.register({
'svg': SVGHandler
});
const div = document.getElementById('viewer-container');
const instance = new FastSvgViewer.default(div, 'assets/icon-github.svg');
class Handler {
/**
* Receives a URL
* Creates the main canvas
* Calls the load function defined by the implementer
* Calls the draw function defined by the implementer
* If you extend the constructor remember to call super
*/
constructor (url) {}
// YOU SHOULD NOT USE THIS FUNCTION
/**
* Creates a canvas with the active Size
* Size should not be modified directly by the implementer
*/
__createCanvas () {}
// YOU SHOULD NOT USE THIS FUNCTION
/**
* Deletes the current instance of the canvas
*/
__deleteCanvas () {}
// YOU SHOULD NOT USE THIS FUNCTION
/**
* Resize the current canvas to the desired size
* @param {[int]} scale [size]
*/
__resize (scale) {}
// YOU SHOULD NOT USE THIS FUNCTION
/**
* Get a square from the canvas matching the provided coordinates
* @param {Number} x [coordinate x of canvas slice to redraw]
* @param {Number} y [coordinate y of canvas slice to redraw]
* @return {ImageData} [New ImageData from canvas slice]
*/
__getAt (x, y) {}
// YOU SHOULD NOT USE THIS FUNCTION
/**
* Returns the transparency map of the current canvas
* @return {ImageData} [New ImageData from canvas slice]
* @private
*/
__getTransparencyMap () {}
/**
* This function should be extended by the implementer
* Beeing in charge of loading all the necesary resources
* To display the image in the viewer
*/
load (BASE_URL) {}
/**
* This method should be extended by the implementer
* Beeing in charge of defining a way of drawing the
* Resources into the Canvas
*/
draw () {}
/**
* This Function should be extended by the implementer
* Beeing in charge of calling the super.clear() method
* and clearing all of the resources loaded in the load()
* function or any other defined function
*/
clear () {}
}
FAQs
Viewer optimized to use huge Image files
The npm package fast-image-viewer receives a total of 0 weekly downloads. As such, fast-image-viewer popularity was classified as not popular.
We found that fast-image-viewer 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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.