How to use the image-size.imageSize 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 webhintio / hint / packages / hint-manifest-icons / src / hint.ts View on Github external
/**
             * sizes can be the string 'any' OR
             * space seperated list of
             * two non-negative integers without leading 0s and separated by 'x' like 144x144
             */
            if (iconSizes === 'any') {
                return false;
            }

            // Working on local environment so no access to the real image for further checking
            if (!iconRawData) {
                return true;
            }

            const specifiedSizes = iconSizes.split(' ');
            const realImage = getImageData(iconRawData);

            /**
             * Do not report if one of the specified size match real icon size
             */
            const sizesMatch = specifiedSizes.some((specifiedSize) => {
                const [widthString, heightString] = specifiedSize.split('x');
                const specifiedWidth = parseInt(widthString);
                const specifiedHeight = parseInt(heightString);

                return specifiedWidth === realImage.width && specifiedHeight === realImage.height;
            });

            if (!sizesMatch && realImage.width && realImage.height) {
                const message = getMessage('realImageSizeNotMatch', context.language, [realImage.width.toString(), realImage.height.toString(), specifiedSizes.toString()]);

                context.report(
github jmerle / png-to-box2d / src / commands / generate.ts View on Github external
'0',
      '--output',
      tracedPath,
      thresholdedAlphaPath,
    );

    // Parse the traced PostScript file and convert it to a JSON file containing all shapes
    const shapesPath = this.getTempPath(inputPath, 'shapes.json');
    this.info(`Converting ${tracedPath} to shape paths`);
    const shapes = await postScriptToShapes(tracedPath, shapesPath, tolerance);

    // Convert the shape data into triangle data
    this.info(`Converting shape paths to triangulated shapes`);
    const triangles = await shapesToTriangulatedShapes(shapes);

    const inputDimensions = await imageSize(inputPath);

    const data: any = {
      width: inputDimensions.width,
      height: inputDimensions.height,
      shapes: triangles,
    };

    if (this.flags.path) {
      const paths: Point[][] = [];

      for (const shape of shapes) {
        const currentPath: Point[] = [];

        if (shape.mainPath !== null) {
          for (const point of shape.mainPath) {
            currentPath.push({
github webhintio / hint / packages / hint-image-optimization-cloudinary / src / hint.ts View on Github external
const analyzeImage = (fetchEnd: FetchEnd) => {
            if (!configured) {
                return;
            }

            const { response } = fetchEnd;

            try {
                // TODO: Find a better way than doing this to detect if it's an image
                getImageData(response.body.rawContent);

                uploads.push(processImage(fetchEnd));
            } catch (e) {
                if (e instanceof TypeError) {
                    // Not an image, ignoring
                }
            }
        };
github webhintio / hint / packages / hint-apple-touch-icons / src / hint.ts View on Github external
/*
             * Notes:
             *
             *  * Async version of `image-size` doesn't work if the
             *    input is a Buffer.
             *
             *    https://github.com/image-size/image-size/tree/4c527ba608d742fbb29f6d9b3c77b831b069cbb2#asynchronous
             *
             * * `image-size` will throw a `TypeError` error if it does
             *    not understand the file type or the image is invalid
             *    or corrupted.
             */

            try {
                image = getImageData(response.body.rawContent);
            } catch (e) {
                if (e instanceof TypeError) {
                    const message = getMessage('invalidPNG', context.language, appleTouchIconHref);

                    context.report(
                        resource,
                        message,
                        { element: appleTouchIcon, severity: Severity.error }
                    );
                } else {
                    debug(`'getImageData' failed for '${appleTouchIconURL}'`);
                }

                return;
            }

image-size

get dimensions of any image file

MIT
Latest version published 5 hours ago

Package Health Score

88 / 100
Full package analysis