src/managers/image-generator.js
/**
   * Processes a text item of the template by adding and merging a text layer onto the base image.
   * @private
   * @param   {Object}          itemConfig the part of the image template defined as a JSON
   * @param   {DepreciatedJimp} baseImg    the base image
   * @param   {Object}          params     the parameters to be applied for the base image
   * @returns {Promise}                    nothing
   */
Processes a text item of the template by adding and merging a text layer onto the base image.
Processes a text item of the template by adding and merging a text layer onto the base image .
async processTextTemplate(itemConfig, baseImg, params) {
    let x = 0;
    let y = 0;
    if (itemConfig.margin) {
      x = baseImg.getWidth() / 100 * itemConfig.margin.left || 0;
      y = baseImg.getHeight() / 100 * itemConfig.margin.top || 0;
      const x2 = baseImg.getWidth() - baseImg.getWidth() / 100 * itemConfig.margin.right || 0;
      const y2 = baseImg.getHeight() - baseImg.getHeight() / 100 * itemConfig.margin.bottom || 0;
      itemConfig.style.customHeight = y2 - y;
      itemConfig.style.maxWidth = x2 - x;
    }
    if (params.fontSize) {
      itemConfig.style.fontSize = params.fontSize;
      itemConfig.style.lineHeight = Math.round(params.fontSize * FONT_SIZE_TO_LINE_HEIGHT);
    }
    const picText = await TextToImage.generate(params.text, itemConfig.style || {});
    const picTextBuffer = Buffer.from(picText.split(',')[1], 'base64');
    const jimpText = await Jimp.read(picTextBuffer);
    if (itemConfig.rotate) {
      jimpText.rotate(itemConfig.rotate);
    }
    if (itemConfig.shear) {
      this.shear(jimpText, itemConfig.shear);
    }
    baseImg.composite(jimpText, x, y);
  }
async processTextTemplate ( itemConfig , baseImg , params ) { let x = 0 ; let y = 0 ; if ( itemConfig . margin ) { x = baseImg . getWidth ( ) / 100 * itemConfig . margin . left || 0 ; y = baseImg . getHeight ( ) / 100 * itemConfig . margin . top || 0 ; const x2 = baseImg . getWidth ( ) - baseImg . getWidth ( ) / 100 * itemConfig . margin . right || 0 ; const y2 = baseImg . getHeight ( ) - baseImg . getHeight ( ) / 100 * itemConfig . margin . bottom || 0 ; itemConfig . style . customHeight = y2 - y ; itemConfig . style . maxWidth = x2 - x ; } if ( params . fontSize ) { itemConfig . style . fontSize = params . fontSize ; itemConfig . style . lineHeight = Math . round ( params . fontSize * FONT_SIZE_TO_LINE_HEIGHT ) ; } const picText = await TextToImage . generate ( params . text , itemConfig . style || { } ) ; const picTextBuffer = Buffer . from ( picText . split ( ',' ) [ 1 ] , 'base64' ) ; const jimpText = await Jimp . read ( picTextBuffer ) ; if ( itemConfig . rotate ) { jimpText . rotate ( itemConfig . rotate ) ; } if ( itemConfig . shear ) { this . shear ( jimpText , itemConfig . shear ) ; } baseImg . composite ( jimpText , x , y ) ; }
Processes a text item of the template by adding and merging a text layer onto the base image.
Processes a text item of the template by adding and merging a text layer onto the base image .
// Override font size