@@ -13,7 +13,13 @@ import { getExtension } from '@/lib/paths';
1313import { filterOutNullable } from '@/lib/typescript' ;
1414import { getCacheTag } from '@gitbook/cache-tags' ;
1515import type { GitBookSiteContext } from '@v2/lib/context' ;
16- import { getResizedImageURL } from '@v2/lib/images' ;
16+ import {
17+ type ResizeImageOptions ,
18+ SizableImageAction ,
19+ checkIsSizableImageURL ,
20+ getResizedImageURL ,
21+ resizeImage ,
22+ } from '@v2/lib/images' ;
1723
1824/**
1925 * Render the OpenGraph image for a site content.
@@ -178,7 +184,10 @@ export async function serveOGImage(baseContext: GitBookSiteContext, params: Page
178184 }
179185
180186 return await fetchImage (
181- useLightTheme ? customization . header . logo . light : customization . header . logo . dark
187+ useLightTheme ? customization . header . logo . light : customization . header . logo . dark ,
188+ {
189+ height : 60 ,
190+ }
182191 ) ;
183192 } ;
184193
@@ -353,14 +362,22 @@ const SUPPORTED_IMAGE_TYPES = [
353362 * Fetch an image from a URL and return a base64 encoded string.
354363 * We do this as @vercel/og is otherwise failing on SVG images referenced by a URL.
355364 */
356- async function fetchImage ( url : string ) {
365+ async function fetchImage ( url : string , options ?: ResizeImageOptions ) {
357366 // Skip early some images to avoid fetching them
358367 const parsedURL = new URL ( url ) ;
359368 if ( UNSUPPORTED_IMAGE_EXTENSIONS . includes ( getExtension ( parsedURL . pathname ) . toLowerCase ( ) ) ) {
360369 return null ;
361370 }
362371
363- const response = await fetch ( url ) ;
372+ // We use the image resizer to normalize the image format to PNG.
373+ // as @vercel /og can sometimes fail on some JPEG images.
374+ const response =
375+ checkIsSizableImageURL ( url ) !== SizableImageAction . Resize
376+ ? await fetch ( url )
377+ : await resizeImage ( url , {
378+ ...options ,
379+ format : 'png' ,
380+ } ) ;
364381
365382 // Filter out unsupported image types
366383 const contentType = response . headers . get ( 'content-type' ) ;
0 commit comments