@@ -33,11 +33,11 @@ async function optimizeImage(
3333 const buffer = await res . arrayBuffer ( ) ;
3434 const optimizedBuffer = await sharp ( buffer )
3535 . resize ( { width } )
36- . png ( { quality : 75 } )
36+ . jpeg ( { quality : 75 } )
3737 . toBuffer ( ) ;
3838 const base64String = optimizedBuffer . toString ( "base64" ) ;
3939
40- return `data:image/png ;base64,${ base64String } ` ;
40+ return `data:image/jpeg ;base64,${ base64String } ` ;
4141 } catch ( err ) {
4242 console . log ( "Error converting image to base64 string." , {
4343 err,
@@ -67,8 +67,7 @@ export async function createMetaImage(options: MetaImageOptions) {
6767 const imageSrc = image ?. sourceUrl || image ?. mediaItemUrl ;
6868 const optimizedSrc = await optimizeImage ( imageSrc , size ) ;
6969 const seravekSemiBold = await loadFont ( title ) ;
70-
71- return new ImageResponse (
70+ const png = await new ImageResponse (
7271 < div
7372 style = { {
7473 display : "flex" ,
@@ -93,7 +92,7 @@ export async function createMetaImage(options: MetaImageOptions) {
9392 xmlns = "http://www.w3.org/2000/svg"
9493 style = { {
9594 position : "absolute" ,
96- top : 45 ,
95+ bottom : 0 ,
9796 right : size . width - ( 375 + 920 ) ,
9897 } }
9998 >
@@ -377,7 +376,14 @@ export async function createMetaImage(options: MetaImageOptions) {
377376 ] ,
378377 } ) ,
379378 } ,
380- ) ;
379+ ) . arrayBuffer ( ) ;
380+ const jpeg = await sharp ( Buffer . from ( png ) ) . jpeg ( { quality : 80 } ) . toBuffer ( ) ;
381+
382+ return new Response ( jpeg as unknown as BodyInit , {
383+ headers : {
384+ "Content-Type" : "image/jpeg" ,
385+ } ,
386+ } ) ;
381387}
382388
383389export default createMetaImage ;
0 commit comments