src/managers/image-generator.js
/**
   * Prepares the base image according to the template requirements.
   * @private
   * @param   {DepreciatedJimp} baseImg        the base image
   * @param   {Object}          params         the parameters to be applied for the base image
   * @param   {Object}          templateConfig the image template defined as a JSON
   * @returns {Promise}                        nothing
   */
Prepares the base image according to the template requirements.
Prepares the base image according to the template requirements .
async prepareBaseImage(baseImg, params, templateConfig) {
    await baseImg.quality(JPEG_QUALITY);
    if (templateConfig.input) {
      if (templateConfig.input.type === 'fixed') {
        const basePicRatio = baseImg.getWidth() / baseImg.getHeight();
        const inputRatio = templateConfig.input.width / templateConfig.input.height;
        if (basePicRatio <= inputRatio) {
          await baseImg.resize(templateConfig.input.width, Jimp.AUTO);
        } else {
          await baseImg.resize(Jimp.AUTO, templateConfig.input.height);
        }
        let x = (baseImg.getWidth() - templateConfig.input.width) / 2 + params.xShift || 0;
        let y = (baseImg.getHeight() - templateConfig.input.height) / 2 + params.yShift || 0;
        x = x < 0 ? 0 : x;
        y = y < 0 ? 0 : y;
        await baseImg.crop(x, y, templateConfig.input.width, templateConfig.input.height);
      }
    }
  }
async prepareBaseImage ( baseImg , params , templateConfig ) { await baseImg . quality ( JPEG_QUALITY ) ; if ( templateConfig . input ) { if ( templateConfig . input . type === 'fixed' ) { const basePicRatio = baseImg . getWidth ( ) / baseImg . getHeight ( ) ; const inputRatio = templateConfig . input . width / templateConfig . input . height ; if ( basePicRatio <= inputRatio ) { await baseImg . resize ( templateConfig . input . width , Jimp . AUTO ) ; } else { await baseImg . resize ( Jimp . AUTO , templateConfig . input . height ) ; } let x = ( baseImg . getWidth ( ) - templateConfig . input . width ) / 2 + params . xShift || 0 ; let y = ( baseImg . getHeight ( ) - templateConfig . input . height ) / 2 + params . yShift || 0 ; x = x < 0 ? 0 : x ; y = y < 0 ? 0 : y ; await baseImg . crop ( x , y , templateConfig . input . width , templateConfig . input . height ) ; } } }
Prepares the base image according to the template requirements.
Prepares the base image according to the template requirements .