next/image blocks external hostnames by default, so a logo from img.logo.dev throws Invalid src prop ... hostname is not configured. One remotePatterns entry fixes it. This page covers that config, the env var for your key, and the canvas caveat.
Prerequisites
- A Logo.dev publishable key (
pk_…). - Next.js 12.3 or later (any version with
remotePatterns).
Allow img.logo.dev in next.config.js
Add Restart the dev server after changing
img.logo.dev to images.remotePatterns so the Image Optimization API fetches from it:next.config.js
next.config.js. Next reads the config once at startup.Store your publishable key in an env var
A publishable key is built for client-side code, so you can expose it in the browser. Prefix it with
NEXT_PUBLIC_ to make it available to client components:.env.local
Skip the optimizer
next/image re-encodes the logo through Next’s optimizer. Logo.dev already serves sized, cached images from a CDN, so a plain <img> (or unoptimized) is often simpler and avoids a second hop:
size, format, and theme parameters on the URL to control output instead of the optimizer.
Canvas and OG images
Drawing a logo onto a<canvas> taints it unless you set crossorigin="anonymous". Generating Open Graph images with next/og renders on the server, where the canvas rules don’t apply, but you still fetch the logo over the network. CORS, canvas, and CSP covers both.
CORS, canvas, and Content Security Policy
Untaint a canvas and allow img.logo.dev in your CSP.