+
https://github.com/mohdlatif
+

+
+ );
+ }
+
+ return new ImageResponse(SocialCardTemplate, {
+ width: 1200,
+ height: 630,
+ fonts: Array.isArray(font) ? [...font] : [font],
+ });
+ } catch (error: any) {
+ console.error('OG Image generation error:', error);
+ return c.json({ error: 'Failed to generate image', details: error.message }, 500);
+ }
+});
+```
+
+```typescript title="src/index.ts"
+import { Hono } from 'hono';
+import og from './og';
+import { logger } from 'hono/logger';
+import { cache } from 'hono/cache';
+
+const app = new Hono()
+ .use('*', logger())
+ // .use(
+ // '*',
+ // cache({
+ // cacheName: async (c) => {
+ // const url = new URL(c.req.url);
+ // const params = url.searchParams.toString();
+ // return `${c.req.method} ${url.pathname}${params}`;
+ // },
+ // cacheControl: 'max-age=86400', // 24 hour
+ // })
+ // )
+ .get('/', (c) => {
+ return c.text('Hello from OG Image Generator on Cloudflare Worker!');
+ })
+ .route('og', og);
+
+export default app;
+```
+
+```typescript title="src/style.css"
+/* src/styles.css */
+@import 'tailwindcss/base';
+@import 'tailwindcss/components';
+@import 'tailwindcss/utilities';
+```
+
+```typescript title="worker-configuration.d.ts"
+// Generated by Wrangler by running `wrangler types --env-interface CloudflareBindings`
+
+interface CloudflareBindings {
+ ASSETS: Fetcher;
+}
+```
+
+The complete source code is available on [GitHub](https://github.com/mohdlatif/og-image-generator-cloudflare-worker).
+
+## Related resources
+
+- [Cloudflare Workers documentation](/workers/)
+- [Hono framework](https://hono.dev/)
+- [Vercel OG Image Generation](https://vercel.com/docs/functions/og-image-generation)
+- [Cloudflare page plugin vercel/og](/pages/functions/plugins/vercel-og/)
+- [Tailwind CSS](https://tailwindcss.com/)