bde148f286
* wip * some extra fixes * stuff kinda works? * need to figure out mocks * need to figure out mocks * fix db listener * gqlgen fix * minor gqlgen watch adjustment * lint fixes * delete old codegen file * converting migrations to ESM * getModuleDIrectory * vitest sort of works * added back ts-vitest * resolve gql double load * fixing test timeout configs * TSC lint fix * fix automate tests * moar debugging * debugging * more debugging * codegen update * server works * yargs migrated * chore(server): getting rid of global mocks for Server ESM (#5046) * got rid of email mock * got rid of comment mocks * got rid of multi region mocks * got rid of stripe mock * admin override mock updated * removed final mock * fixing import.meta.resolve calls * another import.meta.resolve fix * added requested test * nyc ESM fix * removed unneeded deps + linting * yarn lock forgot to commit * tryna fix flakyness * email capture util fix * sendEmail fix * fix TSX check * sender transporter fix + CR comments * merge main fix * test fixx * circleci fix * gqlgen bigint fix * error formatter fix * more error formatting improvements * esmloader added to Dockerfile * more dockerfile fixes * bg jobs fix
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
import sharp from 'sharp'
|
|
import xmlescape from 'xml-escape'
|
|
import pixelWidth from 'string-pixel-width'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
type SharpInput =
|
|
| Buffer
|
|
| ArrayBuffer
|
|
| Uint8Array
|
|
| Uint8ClampedArray
|
|
| Int8Array
|
|
| Uint16Array
|
|
| Int16Array
|
|
| Uint32Array
|
|
| Int32Array
|
|
| Float32Array
|
|
| Float64Array
|
|
| string
|
|
|
|
export async function makeOgImage(
|
|
previewBufferOrFilename: SharpInput,
|
|
streamName: string
|
|
) {
|
|
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 += '...'
|
|
}
|
|
|
|
const logo = await sharp(
|
|
fileURLToPath(
|
|
import.meta.resolve('#/assets/previews/images/speckle_logo_and_text.png')
|
|
)
|
|
)
|
|
.resize({ height: panelHeight })
|
|
.toBuffer()
|
|
|
|
const topPanel = Buffer.from(`
|
|
<svg width="${imgWidth}" height="${panelHeight + 2 * panelPadding}">
|
|
<defs>
|
|
<filter id="dropshadow" height="130%">
|
|
<feGaussianBlur in="SourceAlpha" stdDeviation="3"/>
|
|
<feOffset dx="0" dy="5" result="offsetblur"/>
|
|
<feComponentTransfer>
|
|
<feFuncA type="linear" slope="0.3"/>
|
|
</feComponentTransfer>
|
|
<feMerge>
|
|
<feMergeNode/>
|
|
<feMergeNode in="SourceGraphic"/>
|
|
</feMerge>
|
|
</filter>
|
|
</defs>
|
|
|
|
<rect x="${panelPadding}" y="${panelPadding}" width="${panelWidth}" height="${panelHeight}" fill="#fff" rx="15" filter="url(#dropshadow)" />
|
|
<text x="${panelPadding + 305}" y="${
|
|
panelPadding + 60
|
|
}" fill="#000" font-family="DejaVu Sans, sans-serif" font-size="48px">
|
|
${xmlescape(title)}
|
|
</text>
|
|
</svg>
|
|
`)
|
|
|
|
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()
|
|
}
|