How to use save-pixels - 9 common examples

To help you get started, we’ve selected a few save-pixels 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 uber-web / loaders.gl / modules / polyfills / src / images-node / encode-image.node.js View on Github external
export function encodeImageToStreamNode(image, options) {
  // Support MIME type strings
  const type = options.type ? options.type.replace('image/', '') : 'jpeg';
  const pixels = ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);

  // Note: savePixels returns a stream
  return savePixels(pixels, type, options);
}
github transitive-bullshit / primitive / lib / context.js View on Github external
export const saveImage = async (image, filename, opts) => {
  ow(image, ow.object.label('image').nonEmpty)
  ow(filename, ow.string.label('filename').nonEmpty)

  const pixels = ndarray(image.data, [ image.height, image.width, 4 ])
  const parts = filename.split('.')
  const format = parts[parts.length - 1]
  const stream = savePixels(pixels.transpose(1, 0, 2), format)
  return pump(stream, fs.createWriteStream(filename))
}
github lqs469 / jump / index.js View on Github external
const zoom = (x, y) => (rgb, value) => {
        for (let i = -1; i < 2; i++) {
          for (let j = -1; j < 2; j++) {
            p.set(x + i, y + j, rgb, value)
          }
        }
      }

      points.forEach((point) => {
        zoom(from.x, from.y)(point.index, point.rgb)
        zoom(target.x, target.y)(point.index, point.rgb)
      })

      const writableFile = fs.createWriteStream(`lastScreen${screenshotIndex}.png`)
      savePixels(p, 'png').pipe(writableFile)
      console.log(`[lastScreen${screenshotIndex}.png saved]`)
      resolve()
    })
  })
github uber / luma.gl / modules / io / src / node-io / headless-io.js View on Github external
export function compressImage(image, type = 'png') {
  return savePixels(
    ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0),
    type.replace('image/', '')
  );
}
github alexpeattie / xdog-sketch / src / xdog.js View on Github external
result.data().then(sketchPixels => {
      const pixelArray = ndarray(sketchPixels, shape)
      streamToPromise(savePixels(pixelArray, 'png')).then(buffer => {
        const image = 'data:image/png;base64,' + buffer.toString('base64')
        resolve(image)
      })
    })
  })
github gre / gl-transition-libs / packages / gl-transition-scripts / src / gl-transition-render.js View on Github external
new Promise(success => {
        transitions[tIndex].draw(
          progress,
          from,
          to,
          width,
          height,
          transitionParams[tIndex]
        );
        gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, data);
        const stream = savePixels(pixels, "png").pipe(outStream);
        stream.on("finish", success);
      });
github scijs / image-rotate / example / example.js View on Github external
//Load input image
var baboon = require("luminance")(require("baboon-image"))

//Allocate storage for result
var result = require("zeros")([512, 512])

//Rotate the image
require("../rotate.js")(result, baboon, Math.PI / 6.0)

//Save the result
require("save-pixels")(result, "png").pipe(process.stdout)
github scijs / ndarray-resample / example / example.js View on Github external
var baboon = require("luminance")(require("baboon-image"))
var x = require("zeros")([256,256])
require("../resample.js")(x, baboon)
require("save-pixels")(x, "png").pipe(process.stdout)
github scijs / distance-transform / example / example.js View on Github external
//Generate some shape as a binary voxel image
var x = require("zeros")([256, 256])
x.set(128, 128, 1)

//Distance transform
require("../dt.js")(x)

//Save result
require("save-pixels")(x, "png").pipe(process.stdout)

save-pixels

Saves an ndarray as an image to a file

MIT
Latest version published 3 years ago

Package Health Score

54 / 100
Full package analysis

Popular save-pixels functions