diff --git a/README.md b/README.md index b103dab97..cc952391e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -![CodeImage logo](assets/banner.png?raw=true) + + + CodeImage: beautify your code screenshots, then animate them + > Create elegant code screenshots of your source code. diff --git a/apps/codeimage/index.html b/apps/codeimage/index.html index 34917f9c7..3ad370f02 100644 --- a/apps/codeimage/index.html +++ b/apps/codeimage/index.html @@ -4,7 +4,8 @@ - + + - + + - + - - + - - - - - - - - - - - - - - - - - - - - + + + + + + + - \ No newline at end of file + + + + + + + + + + + + diff --git a/apps/codeimage/public/assets/favicon.ico b/apps/codeimage/public/assets/favicon.ico index 5edef4b93..b707ac73f 100644 Binary files a/apps/codeimage/public/assets/favicon.ico and b/apps/codeimage/public/assets/favicon.ico differ diff --git a/apps/codeimage/public/assets/favicon.svg b/apps/codeimage/public/assets/favicon.svg index a7a7a79bd..d32707a4f 100644 --- a/apps/codeimage/public/assets/favicon.svg +++ b/apps/codeimage/public/assets/favicon.svg @@ -1,18 +1,16 @@ - - - `, + ); + await page.locator('img').evaluate(img => img.decode()); + return page.screenshot({omitBackground: true}); +} + +async function renderLogo(page, file, width) { + const svg = await dataUri(file, 'image/svg+xml'); + const [, , vbWidth, vbHeight] = (await read(file)) + .toString() + .match(/viewBox="([^"]+)"/)[1] + .split(' ') + .map(Number); + const height = Math.round((width * vbHeight) / vbWidth); + await page.setViewportSize({width, height}); + await page.setContent( + ``, + ); + await page.locator('img').evaluate(img => img.decode()); + return page.screenshot({omitBackground: true}); +} + +function ico(images) { + const header = Buffer.alloc(6); + header.writeUInt16LE(0, 0); + header.writeUInt16LE(1, 2); + header.writeUInt16LE(images.length, 4); + let offset = 6 + images.length * 16; + const entries = images.map(({size, png}) => { + const entry = Buffer.alloc(16); + entry.writeUInt8(size >= 256 ? 0 : size, 0); + entry.writeUInt8(size >= 256 ? 0 : size, 1); + entry.writeUInt16LE(1, 4); + entry.writeUInt16LE(32, 6); + entry.writeUInt32LE(png.length, 8); + entry.writeUInt32LE(offset, 12); + offset += png.length; + return entry; + }); + return Buffer.concat([header, ...entries, ...images.map(i => i.png)]); +} + +async function main() { + const browser = await chromium.launch(); + const page = await browser.newPage({deviceScaleFactor: 1}); + + const iconSizes = [16, 32, 48, 64, 128, 192, 256, 512, 1024]; + const icons = {}; + for (const size of iconSizes) { + icons[size] = await renderSvg(page, 'mark.svg', size); + await out(`icons/icon-${size}.png`, icons[size]); + } + await out( + 'icons/favicon.ico', + ico([16, 32, 48].map(size => ({size, png: icons[size]}))), + ); + await out('icons/favicon.svg', await read('mark.svg')); + await out( + 'icons/apple-touch-icon.png', + await renderSvg(page, 'mark-square.svg', 180), + ); + for (const size of [192, 512]) { + await out( + `icons/icon-${size}-maskable.png`, + await renderSvg(page, 'mark-maskable.svg', size), + ); + } + + for (const file of [ + 'logo-on-dark', + 'logo-on-light', + 'logo-black', + 'logo-white', + 'wordmark-on-dark', + 'wordmark-on-light', + 'wordmark-black', + 'wordmark-white', + ]) { + await out(`logos/${file}.png`, await renderLogo(page, `${file}.svg`, 1888)); + } + for (const file of ['mark', 'mark-black', 'mark-white']) { + await out(`logos/${file}.png`, await renderSvg(page, `${file}.svg`, 1024)); + } + + const codeWindow = ``; + const cliArt = terminal([ + ['comment', 'A file to an image.'], + ['command', `pnpm dlx ${cliPackage} src/example.ts -o example.png`], + ['comment', 'Your diff, marked.'], + ['command', `git diff | pnpm dlx ${cliPackage} --diff -o changes.png`], + ['comment', 'Two files, one animation.'], + [ + 'command', + `pnpm dlx ${cliPackage} before.ts after.ts --animate -o change.gif`, + ], + ]); + + const cards = []; + for (const theme of ['dark', 'light']) { + cards.push({ + file: `social/og-${theme}.png`, + width: 1200, + height: 630, + theme, + layout: ogLayout, + title: + 'Beautify your code screenshots. And now,
animate them.
', + url: 'codeimage.dev', + art: codeWindow, + }); + cards.push({ + file: `social/readme-banner-${theme}.png`, + width: 1280, + height: 420, + theme, + layout: bannerLayout, + title: 'Beautify your code screenshots. Then animate them.', + subtitle: + 'Free and open source. On the web, in your terminal and for agents.', + art: codeWindow, + }); + cards.push({ + file: `social/cli-banner-${theme}.png`, + width: 1280, + height: 420, + theme, + layout: { + ...bannerLayout, + title: 44, + textWidth: 580, + frameX: 628, + frameW: 700, + framePad: 34, + frameY: 70, + }, + title: 'Code images and videos from your terminal.', + subtitle: + 'Renders in Node, with no browser. Secrets are redacted by default.', + art: cliArt, + }); + } + cards.push({ + file: 'social/github-social-preview.png', + width: 1280, + height: 640, + theme: 'dark', + layout: socialPreviewLayout, + title: 'Beautify your code screenshots. And now,
animate them.
', + url: 'github.com/riccardoperra/codeimage', + art: codeWindow, + }); + + const cardPage = await browser.newPage({deviceScaleFactor: 2}); + for (const card of cards) { + await cardPage.setViewportSize({width: card.width, height: card.height}); + await cardPage.setContent(await social(card)); + await cardPage.evaluate(() => document.fonts.ready); + await out(card.file, await cardPage.screenshot()); + } + + await browser.close(); + + const app = join(root, 'apps/codeimage/public'); + await copyFile( + join(brand, 'icons/favicon.ico'), + join(app, 'assets/favicon.ico'), + ); + await copyFile( + join(brand, 'icons/favicon.svg'), + join(app, 'assets/favicon.svg'), + ); + await copyFile( + join(brand, 'icons/apple-touch-icon.png'), + join(app, 'pwa/apple-icon-180.png'), + ); + await copyFile( + join(brand, 'icons/icon-192-maskable.png'), + join(app, 'pwa/manifest-icon-192.maskable.png'), + ); + await copyFile( + join(brand, 'icons/icon-512-maskable.png'), + join(app, 'pwa/manifest-icon-512.maskable.png'), + ); + await copyFile( + join(logos, 'logo-on-dark.svg'), + join(app, 'assets/codeimage-logo-blue-svg-v1.svg'), + ); +} + +await main(); diff --git a/scripts/brand/cards.mjs b/scripts/brand/cards.mjs new file mode 100644 index 000000000..49b0dc529 --- /dev/null +++ b/scripts/brand/cards.mjs @@ -0,0 +1,132 @@ +import {readFile} from 'node:fs/promises'; +import {join} from 'node:path'; +import {dataUri, fonts} from './paths.mjs'; + +const themes = { + dark: { + bg: '#0e0e10', + fg: '#f4f4f5', + muted: '#a1a1aa', + accent: '#3b9eff', + grid: 'rgba(255,255,255,.11)', + glow: [0.38, 0.3], + shadow: 0.7, + logo: 'logo-on-dark.svg', + }, + light: { + bg: '#f1f1f1', + fg: '#18181b', + muted: '#5f5f66', + accent: '#0a7ad6', + grid: 'rgba(0,0,0,.09)', + glow: [0.38, 0.3], + shadow: 0.3, + logo: 'logo-on-light.svg', + }, +}; + +const frameGradient = + 'linear-gradient(152deg, rgb(222,156,110) 0%, rgb(125,36,242) 100%)'; + +async function fontFaces() { + const weights = {Medium: 500, SemiBold: 600}; + const faces = await Promise.all( + Object.entries(weights).map(async ([name, weight]) => { + const data = ( + await readFile(join(fonts, `Mona-Sans-${name}.woff2`)) + ).toString('base64'); + return `@font-face{font-family:Mona;font-weight:${weight};src:url(data:font/woff2;base64,${data})}`; + }), + ); + return faces.join(''); +} + +export function terminal(lines) { + const escape = s => s.replace(/&/g, '&').replace(/ + kind === 'comment' + ? `
# ${escape(text)}
` + : `
$ ${escape(text)}
`, + ) + .join(''); + return `
zsh
${rows}
`; +} + +export async function social({ + width, + height, + theme, + layout, + title, + subtitle, + url, + art, +}) { + const t = themes[theme]; + const logo = await dataUri(t.logo, 'image/svg+xml'); + const l = layout; + return ` +
+

${title}

${subtitle ? `

${subtitle}

` : ''}
+${url ? `
${url}
` : ''} +
${art}
`; +} + +export const ogLayout = { + pad: 72, + top: 72, + textWidth: 440, + logo: 44, + title: 52, + gap: 70, + sub: 22, + subGap: 20, + frameX: 612, + frameY: 70, + frameW: 620, + framePad: 44, + glowX: 50, + glowW: 420, + glowH: 360, +}; + +export const bannerLayout = { + ...ogLayout, + top: 64, + title: 48, + gap: 40, + textWidth: 600, + frameX: 760, + frameY: 56, + frameW: 540, + framePad: 38, + glowX: 62, +}; + +export const socialPreviewLayout = { + ...ogLayout, + pad: 80, + top: 80, + frameX: 660, + frameY: 80, + frameW: 640, +}; diff --git a/scripts/brand/paths.mjs b/scripts/brand/paths.mjs new file mode 100644 index 000000000..34f5567a0 --- /dev/null +++ b/scripts/brand/paths.mjs @@ -0,0 +1,21 @@ +import {readFile} from 'node:fs/promises'; +import {dirname, join, resolve} from 'node:path'; +import {fileURLToPath} from 'node:url'; + +export const root = resolve(dirname(fileURLToPath(import.meta.url)), '../..'); +export const brand = join(root, 'assets/brand'); +export const source = join(brand, 'source'); +export const logos = join(brand, 'logos'); +export const fonts = join(root, 'apps/website/public/fonts'); + +export const read = file => + readFile( + join( + /^(mark|logo|wordmark)(-(black|white|on-dark|on-light))?\.svg$/.test(file) + ? logos + : source, + file, + ), + ); +export const dataUri = async (file, type) => + `data:${type};base64,${(await read(file)).toString('base64')}`;