src/managers/image-generator.js
/**
   * Processes 'fonts' blocks of the image template config.
   * Tries to download and register declared fonts in the local system.
   * @private
   * @param   {Object}  templateConfig the image template defined as a JSON
   * @returns {Promise}                nothing
   */
Processes 'fonts' blocks of the image template config.
Tries to download and register declared fonts in the local system.
@private
@param   {Object}  templateConfig the image template defined as a JSON
@returns {Promise}                nothing
Processes ' fonts ' blocks of the image template config . Tries to download and register declared fonts in the local system . @private @param { Object } templateConfig the image template defined as a JSON @returns { Promise } nothing
async addFonts(templateConfig) {
    if (templateConfig.fonts && Array.isArray(templateConfig.fonts)) {
      for (const font of templateConfig.fonts) {
        const fileName = crypto.createHash('md5').update(font.url).digest('hex');
        const filePath = FILE_CACHE_FOLDER + fileName;
        try {
          if (!fs.existsSync(filePath)) {
            await this.downloadFileWithSizeLimit(font.url, filePath, MAX_FONT_FILE_SIZE);
          }
          Canvas._registerFont(filePath, { family: font.name });
        } catch (error) {
          this.context.log.e(`ImageGenerator: Failed to download and include font ${font.url} with
          message: ${error}, stack: ${error.stack}`);
          throw error;
        }
      }
    }
  }
async addFonts ( templateConfig ) { if ( templateConfig . fonts && Array . isArray ( templateConfig . fonts ) ) { for ( const font of templateConfig . fonts ) { const fileName = crypto . createHash ( 'md5' ) . update ( font . url ) . digest ( 'hex' ) ; const filePath = FILE_CACHE_FOLDER + fileName ; try { if ( ! fs . existsSync ( filePath ) ) { await this . downloadFileWithSizeLimit ( font . url , filePath , MAX_FONT_FILE_SIZE ) ; } Canvas . _registerFont ( filePath , { family : font . name } ) ; } catch ( error ) { this . context . log . e ( ` ${ font . url } ${ error } ${ error . stack } ` ) ; throw error ; } } } }
Processes 'fonts' blocks of the image template config.
Processes ' fonts ' blocks of the image template config .