/* istanbul ignore file */ 'use strict' const sharp = require('sharp') const xmlescape = require('xml-escape') const pixelWidth = require('string-pixel-width') // const { logger } = require('@/logging/logging') module.exports = { async makeOgImage(previewBufferOrFilename, streamName) { const imgWidth = 1200 const imgHeight = 627 const panelPadding = 20 const panelWidth = imgWidth - 2 * panelPadding const panelHeight = 80 let title = '/ ' + streamName const maxTitleSize = 750 if (pixelWidth(title, { font: 'open sans', size: 48 }) > maxTitleSize) { while (pixelWidth(title, { font: 'open sans', size: 48 }) > maxTitleSize) { title = title.slice(0, -1) } title += '...' } // logger.debug( streamName, pixelWidth( title, { font: 'open sans', size: 48 } ), ' / ', imgWidth - 2 * panelPadding - 305 ) const logo = await sharp( require.resolve('#/assets/previews/images/speckle_logo_and_text.png') ) .resize({ height: panelHeight }) .toBuffer() const topPanel = Buffer.from(` ${xmlescape(title)} `) // return await sharp(previewBufferOrFilename) .resize({ width: imgWidth, height: imgHeight }) .composite([ { input: topPanel, top: 0, left: 0 }, { input: logo, left: panelPadding + 10, top: panelPadding } ]) .png() .toBuffer() } }