How to use the jimp function in jimp

To help you get started, we’ve selected a few jimp 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 zinserjan / wdio-screenshot / src / utils / image / jimp.js View on Github external
let x = 0;
    for (const colImage of colImages) {
      image.blit(colImage, x, 0);
      x += colImage.bitmap.width
    }

    imageWidth = image.bitmap.width;
    imageHeight += image.bitmap.height;

    return image;
  });

  const rowImages = await Promise.all(rowImagePromises);

  // merge vertical
  const image = await new Jimp(imageWidth, imageHeight);

  let y = 0;
  for (const rowImage of rowImages) {
    image.blit(rowImage, 0, y);
    y += rowImage.bitmap.height;
  }

  // finally get screenshot
  const base64Screenshot = await new Promise((resolve, reject) => {
    image.getBuffer(Jimp.MIME_PNG,function (err, buffer) {
      if (err) {
        return reject(err);
      }
      return resolve(buffer.toString('base64'));
    })
  });
github lavyun / better-mock / src / random / image.ts View on Github external
const generateImage = new Promise((resolve, reject) => {
    new Jimp(width, height, background, (err, image) => {
      if (err) {
        reject(err)
      } else {
        Jimp.loadFont(fontPath).then(font => {
          // 文字的真实宽高
          const measureWidth = Jimp.measureText(font, text)
          const measureHeight = Jimp.measureTextHeight(font, text, width)
          // 文字在画布上的目标 x, y
          const targetX = width <= measureWidth ? 0 : (width - measureWidth) / 2
          const targetY = height <= measureHeight ? 0 : (height - measureHeight) / 2
          
          image.print(font, targetX, targetY, text)
          image.getBufferAsync(Jimp.MIME_PNG).then(buffer => {
            resolve('data:image/png;base64,' + buffer.toString('base64'))
          })
        })
github dan335 / nimp / classes / nodes / image / Gradient.js View on Github external
height = Math.max(1, height);

    if (!colorA.isValid()) {
      colorA = tinycolor('#000');
    }

    if (!colorB.isValid()) {
      colorB = tinycolor('#fff');
    }

    if (this.isInsideALoop) {
      let image = new Jimp(width, height, '#000');
      this.image = this.createGradient(image, colorA, colorB);
      super.run(inputThatTriggered);
    } else {
      new Jimp(width, height, '#000', (error, image) => {
        if (error) {
          console.log(error);
        } else {
          this.image = this.createGradient(image, colorA, colorB);
          super.run(inputThatTriggered);
        }
      })
    }

  }
github dan335 / nimp / classes / nodes / image / Simplex.js View on Github external
if (this.inputs[3].number != null) {
      scale = this.inputs[3].number;
    }

    width = Math.max(1, width);
    height = Math.max(1, height);
    scale = Math.max(0.00001, scale);
    scale = Math.min(5, scale);

    if (this.isInsideALoop) {
      let image = new Jimp(width, height);
      this.image = this.writeSimplexToImage(image, seed, scale);
      super.run(inputThatTriggered);
    } else {
      new Jimp(width, height, (error, image) => {
        if (error) {
          console.log(error);
        } else {
          this.image = this.writeSimplexToImage(image, seed, scale);
          super.run(inputThatTriggered);
        }
      })
    }
  }
github dan335 / nimp / classes / nodes / image / Line.js View on Github external
lineWidth = this.inputs[6].number;
    }

    width = Math.max(1, width);
    height = Math.max(1, height);

    lineWidth = Math.max(1, lineWidth);

    const tc = tinycolor(hexColor);
    this.color = '#fff';
    if (tc.isValid()) {
      this.color = tc.toHex8String();
    }

    if (this.isInsideALoop) {
      let image = new Jimp(width, height, 0x00000000);
      this.image = this.createLine(image, width, height, x1, y1, x2, y2, this.color, lineWidth);
      super.run(inputThatTriggered);
    } else {
      new Jimp(width, height, 0x00000000, (error, image) => {
        if (error) {
          console.log(error);
        } else {
          this.image = this.createLine(image, width, height, x1, y1, x2, y2, this.color, lineWidth);
          super.run(inputThatTriggered);
        }
      })
    }

  }
github dan335 / nimp / classes / nodes / image / Simplex.js View on Github external
if (this.inputs[2].number != null) {
      seed = this.inputs[2].number;
    }

    if (this.inputs[3].number != null) {
      scale = this.inputs[3].number;
    }

    width = Math.max(1, width);
    height = Math.max(1, height);
    scale = Math.max(0.00001, scale);
    scale = Math.min(5, scale);

    if (this.isInsideALoop) {
      let image = new Jimp(width, height);
      this.image = this.writeSimplexToImage(image, seed, scale);
      super.run(inputThatTriggered);
    } else {
      new Jimp(width, height, (error, image) => {
        if (error) {
          console.log(error);
        } else {
          this.image = this.writeSimplexToImage(image, seed, scale);
          super.run(inputThatTriggered);
        }
      })
    }
  }
github dan335 / nimp / classes / nodes / image / Triangle.js View on Github external
if (this.inputs[8].color != null) {
      hexColor = this.inputs[8].color;
    }

    width = Math.max(1, width);
    height = Math.max(1, height);

    const tc = tinycolor(hexColor);
    this.color = '#fff';
    if (tc.isValid()) {
      this.color = tc.toHex8String();
    }

    if (this.isInsideALoop) {
      let image = new Jimp(width, height, 0x00000000);
      this.image = this.createTriangle(image, width, height, x1, y1, x2, y2, x3, y3, this.color);
      super.run(inputThatTriggered);
    } else {
      new Jimp(width, height, 0x00000000, (error, image) => {
        if (error) {
          console.log(error);
        } else {
          this.image = this.createTriangle(image, width, height, x1, y1, x2, y2, x3, y3, this.color);
          super.run(inputThatTriggered);
        }
      })
    }

  }
github dan335 / nimp / classes / nodes / image / Faultline.js View on Github external
}

    if (this.inputs[2].number != null) {
      iterations = this.inputs[2].number;
    }

    width = Math.max(1, width);
    height = Math.max(1, height);
    iterations = Math.max(1, iterations);

    if (this.isInsideALoop) {
      let image = new Jimp(width, height, '#808080');
      this.image = this.createImage(image, iterations);
      super.run(inputThatTriggered);
    } else {
      new Jimp(width, height, '#808080', (error, image) => {
        if (error) {
          console.log(error);
        } else {
          this.image = this.createImage(image, iterations);
          super.run(inputThatTriggered);
        }
      })
    }

  }
github SideProjectGuys / invite-manager-bot / src / example / qr.ts View on Github external
return new Promise(res => {
		return new Jimp(dataUriToBuffer(dataUri), (err, img) => {
			if (err) {
				throw err;
			}
			res(img);
		});
	});
}
github sasakiassociates / png-db / src / PngDBWriter.js View on Github external
let r = 0;
                const b = value % 256;
                let g = Math.floor(value / 256);

                if (g > 255) {
                    r = Math.floor(g / 256);
                    g = g % 256;
                }
                encodedValue = Jimp.rgbaToInt(r, g, b, 255);
            } else {
                encodedValue = Jimp.rgbaToInt(0, 0, value, 255);
            }
            image.setPixelColor(encodedValue, x, y);
        };

        new Jimp(imgSize, imgSize, (err, image) => {
            if (field.treatAsArray) {

                let i = 0;
                for (let y = 0; y < pxSize; y++) {
                    for (let x = 0; x < pxSize; x++) {
                        const record = this.records[i++];
                        if (!record) continue;
                        const arr = record[fieldName];
                        if (!arr) return;
                        let a = 0;
                        for (let ty = 0; ty < numTilesEach; ty++) {
                            for (let tx = 0; tx < numTilesEach; tx++) {
                                if (a < arr.length) {
                                    const value = arr[a];
                                    if (isVal(value)) {
                                        setPixel(image, tx * pxSize + x, ty * pxSize + y, value);