How to use the pureimage.registerFont 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);
    } else { // 0
        ctx.fillText(t, 0, 0);
    }
github ekulabuhov / react-native-canvas / src / Text.js View on Github external
generateFontTexture(callback) {    
    let fnt = PImage.registerFont(this.fontUrl, 'Source Sans Pro');

    this.fontLoading = true;

    fnt.load(() => {
      this.font = fnt.font;
      this.fontScale = 1 / this.font.unitsPerEm * this.fontSize;

      let { img, ctx } = this;

      ctx.clearRect(0, 0, this.textureWidth, this.textureHeight);
      ctx.mode = 'REPLACE'; // replace is used to disable alpha blending
      ctx.setFont('Source Sans Pro', this.fontSize);
      ctx.fillStyle = 'red';

      var charHeight = 20,
        charWidth = 20,
github triplecanopy / b-ber / packages / b-ber-tasks / src / cover / index.js View on Github external
return new Promise(resolve => {
            const img = PureImage.make(this.width, this.height)
            const ctx = img.getContext('2d')
            const font = PureImage.registerFont(path.join(__dirname, this.fontFile), this.fontName)

            return font.load(() => {
                ctx.fillStyle = this.colorBackground
                ctx.fillRect(0, 0, this.width, this.height)

                ctx.font = `${this.fontSize}px '${this.fontName}'`
                ctx.fillStyle = this.colorText

                // add text
                ctx.fillText(this.metadata.title, this.marginLeft, this.getPosY())
                ctx.fillText('', this.marginLeft, this.getPosY())

                ctx.fillText('Creator:', this.marginLeft, this.getPosY())
                ctx.fillText(this.metadata.creator, this.marginLeft, this.getPosY())
                ctx.fillText('', this.marginLeft, this.getPosY())
github vladimiry / ElectronMail / src / electron-main / api / endpoints-builders / tray-icon / lib.ts View on Github external
        await new Promise((resolve) => registerFont(fontFilePath, fontFamily).load(resolve));

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