How to use the image-size/lib/types.forEach function in image-size

To help you get started, we’ve selected a few image-size examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HuasoFoundries / systemjs-less-plugin / imagesize.js View on Github external
typeMap = {};


// load all available handlers

handlers.bmp = require('image-size/lib/types/bmp');
handlers.gif = require('image-size/lib/types/gif');
handlers.jpg = require('image-size/lib/types/jpg');
handlers.png = require('image-size/lib/types/png');
handlers.psd = require('image-size/lib/types/psd');
handlers.svg = require('image-size/lib/types/svg');
handlers.tiff = require('image-size/lib/types/tiff');
handlers.webp = require('image-size/lib/types/webp');

// load all available handlers
types.forEach(function (type) {
    typeMap[type] = handlers[type].detect;
});

var detector = function (buffer, filepath) {
    var type, result;
    for (type in typeMap) {
        result = typeMap[type](buffer, filepath);
        if (result) {
            return type;
        }
    }
};


// Maximum buffer size, with a default of 128 kilobytes.
// TO-DO: make this adaptive based on the initial signature of the image

image-size

get dimensions of any image file

MIT
Latest version published 4 months ago

Package Health Score

80 / 100
Full package analysis