src/managers/image-generator.js
/**
   * Processes an image item of the template by adding and merging an image layer onto the base image.
   * @private
   * @param   {Object}          itemConfig the part of the image template defined as a JSON
   * @param   {Object}          params     the parameters to be applied for the base image
   * @param   {DepreciatedJimp} baseImg    the base image
   * @returns {Promise}                    nothing
   */
Processes an image item of the template by adding and merging an image layer onto the base image.
Processes an image item of the template by adding and merging an image layer onto the base image .
async processImageTemplate(itemConfig, params, baseImg) {
    const tmpPic = await Jimp.read(itemConfig.url);
    if (itemConfig.items !== undefined) {
      await this.composeImage(tmpPic, itemConfig.items, params);
    }
    const blendMode = itemConfig.blend || {};
    let composeX = 0;
    let composeY = 0;
    switch (itemConfig.align) {
      case 'top':
        if (itemConfig.autoscale) {
          tmpPic.scaleToFit(baseImg.getWidth(), Number.MAX_VALUE);
        }
        break;
      case 'left':
        if (itemConfig.autoscale) {
          tmpPic.scaleToFit(Number.MAX_VALUE, baseImg.getHeight());
        }
        break;
      case 'bottom':
        if (itemConfig.autoscale) {
          tmpPic.scaleToFit(baseImg.getWidth(), Number.MAX_VALUE);
        }
        composeX = 0;
        composeY = baseImg.getHeight() - tmpPic.getHeight();
        break;
      case 'right':
        if (itemConfig.autoscale) {
          tmpPic.scaleToFit(Number.MAX_VALUE, baseImg.getHeight());
        }
        composeX = baseImg.getWidth() - tmpPic.getWidth();
        composeY = 0;
        break;
      default:
        if (itemConfig.autoscale) {
          tmpPic.scaleToFit(baseImg.getWidth(), baseImg.getHeight());
        }
    }
    if (itemConfig.rotate) {
      tmpPic.rotate(itemConfig.rotate);
    }
    if (itemConfig.shear) {
      this.shear(tmpPic, itemConfig.shear);
    }
    baseImg.composite(tmpPic, composeX, composeY, blendMode);
  }
async processImageTemplate ( itemConfig , params , baseImg ) { const tmpPic = await Jimp . read ( itemConfig . url ) ; if ( itemConfig . items !== undefined ) { await this . composeImage ( tmpPic , itemConfig . items , params ) ; } const blendMode = itemConfig . blend || { } ; let composeX = 0 ; let composeY = 0 ; switch ( itemConfig . align ) { case 'top' : if ( itemConfig . autoscale ) { tmpPic . scaleToFit ( baseImg . getWidth ( ) , Number . MAX_VALUE ) ; } break ; case 'left' : if ( itemConfig . autoscale ) { tmpPic . scaleToFit ( Number . MAX_VALUE , baseImg . getHeight ( ) ) ; } break ; case 'bottom' : if ( itemConfig . autoscale ) { tmpPic . scaleToFit ( baseImg . getWidth ( ) , Number . MAX_VALUE ) ; } composeX = 0 ; composeY = baseImg . getHeight ( ) - tmpPic . getHeight ( ) ; break ; case 'right' : if ( itemConfig . autoscale ) { tmpPic . scaleToFit ( Number . MAX_VALUE , baseImg . getHeight ( ) ) ; } composeX = baseImg . getWidth ( ) - tmpPic . getWidth ( ) ; composeY = 0 ; break ; default : if ( itemConfig . autoscale ) { tmpPic . scaleToFit ( baseImg . getWidth ( ) , baseImg . getHeight ( ) ) ; } } if ( itemConfig . rotate ) { tmpPic . rotate ( itemConfig . rotate ) ; } if ( itemConfig . shear ) { this . shear ( tmpPic , itemConfig . shear ) ; } baseImg . composite ( tmpPic , composeX , composeY , blendMode ) ; }
Processes an image item of the template by adding and merging an image layer onto the base image.
Processes an image item of the template by adding and merging an image layer onto the base image .
// Recursive call for child items