How to use the pureimage.make function in pureimage

To help you get started, we’ve selected a few pureimage 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 fkei / textavatar / lib / textavatar.js View on Github external
function genTextAvatar(text, outputFilePathOrStream, size, callback) {
  var img = PImage.make(size, size);
  var ctx = img.getContext('2d');

  var font = PImage.registerFont(`${__dirname}/../public/font/mplus-1m-regular.ttf`, 'mplus-1m-regular');
  font.load(function () {
    ctx.fillStyle = getColor(text);
    ctx.fillRect(0, 0, size, size);
    var fontSize = size / 1.5
    ctx.font = `${fontSize}pt 'mplus-1m-regular'`;
    ctx.fillStyle = "#FFFFFF";
    var t = text.substring(0, 2).toUpperCase();

    console.log(size , fontSize)
    if (t.length == 2) { // 2
        ctx.fillText(t, (size / 2) - (fontSize / 2), size / 1.4);
    } else if (t.length == 1) { // 1
        ctx.fillText(t, size / 2 - (fontSize / 4), size / 1.4);
github anvaka / playground / graph-to-vector-field / index.js View on Github external
rect.y2 = rect.y1 + width;
    height = width;
  } else {
    rect.x2 = rect.x1 + height;
    width = height;
  }

  // Now it's time to go over every single pixel and build a matrix of
  // velocities. I don['t really care about performance here, as this is
  // just an experiment.
  console.log('Collecting velocities...')
  var velocities = accumulateVelocities(rect, layout);

  // Now that we have all velocities, let's encode them into texture:
  console.log('Rendering vector field...')
  var scene = PImage.make(width, height);

  var ctx = scene.getContext('2d');
  var imgData = ctx.getImageData();

  for (var x = 0; x < width; ++x) {
    for (var y = 0; y < height; ++y) {
      var encodedVelocity = encodeVelocity(velocities[x][y]);
      imgData.setPixelRGBA_i(x, y, encodedVelocity.r, encodedVelocity.g, encodedVelocity.b, encodedVelocity.a);
    }
  }

  // Texture is ready. Dump it onto the file system:
  var textureName = OUT_IMAGE_NAME + '.png';
  PImage.encodePNGToStream(scene, fs.createWriteStream(textureName)).then(()=> {
      console.log('wrote out the png file to ' + textureName);
      if (saveOriginalLayout) {
github ngageoint / geopackage-js / test / testGeopackage.js View on Github external
fs.readFile(tilePath, function(err, tile) {
          var result = geopackage.addTile(tile, tableName, 0, 0, 0);
          result.should.be.equal(1);
          var canvas;
          if (typeof(process) !== 'undefined' && process.version) {
            canvas = PureImage.make(256, 256);
          } else {
            canvas = document.createElement('canvas');
          }
          GeoPackage.drawXYZTileInCanvas(geopackage, tableName, 0, 0, 0, 256, 256, canvas)
          .then(function(tile) {
            testSetup.diffCanvas(canvas, tilePath, function(err, equal) {
              equal.should.be.equal(true);
              done();
            });
          });
        });
      });
github dtysky / paradise / createNewEffect / index.js View on Github external
function createCover(name) {
  const image = PImage.make(400, 300);
  const ctx = image.getContext('2d');
  ctx.fillStyle = stringAsHueToHSLToRGB(name, 50, 60);
  ctx.fillRect(0, 0, 400, 300);

  return image;
}
github vladimiry / ElectronMail / src / electron-main / api / endpoints-builders / tray-icon / lib.ts View on Github external
function cloneBitmap(input: Pick): Bitmap {
    const output = make(input.width, input.height);

    output.data = Buffer.from(input.data);

    return output;
}
github vladimiry / ElectronMail / src / electron-main / api / endpoints-builders / tray-icon / lib.ts View on Github external
function buildCircle(rad: number, color: string): Bitmap {
    const bitmap = make(rad * 2, rad * 2);
    const ctx = bitmap.getContext("2d");

    ctx.fillStyle = color;
    ctx.beginPath();
    ctx.arc(bitmap.width - rad, bitmap.height - rad, rad, 0, Math.PI * 2, true);
    ctx.closePath();
    ctx.fill();

    return bitmap;
}
github vladimiry / ElectronMail / src / electron-main / api / endpoints-builders / tray-icon / lib.ts View on Github external
const sourceBits = source.data.byteLength / (source.width * source.height);
            const dest = {
                data: Uint8ClampedArray.from(new Array(darwinSize.width * darwinSize.height * sourceBits)),
                ...darwinSize,
            };

            lanczos(
                {
                    data: Uint8ClampedArray.from(source.data),
                    width: source.width,
                    height: source.height,
                },
                dest,
            );

            const result = make(dest.width, dest.height);

            result.data = Buffer.from(dest.data);

            return result;
        }
        : async (source) => source;

pureimage

Pure JS image drawing API based on Canvas. Export to PNG, JPG, and streams.

MIT
Latest version published 6 months ago

Package Health Score

69 / 100
Full package analysis

Similar packages