Generate Open Graph social sharing cards with dynamic titles, descriptions, and branding.
Who this is for
Content platforms and developer blogs use this recipe to generate Open Graph images for social sharing. Define a canvas with your brand background and render the article title, description, and site name — ready for og:image meta tags with consistent, eye-catching previews.
import{IterationLayer}from"iterationlayer";constclient=newIterationLayer({apiKey:"YOUR_API_KEY"});constresult=awaitclient.generateImage({dimensions:{width_in_px:1200,height_in_px:630},output_format:"png",layers:[{index:0,type:"solid-color-background",hex_color:"#0F172A",},{index:1,type:"text",text:"Building Scalable APIs with Elixir",font_name:"Inter",font_size_in_px:48,text_color:"#FFFFFF",font_weight:"Bold",position:{x:80.0,y:120.0},dimensions:{width_in_px:1040,height_in_px:200},},{index:2,type:"text",text:"A practical guide to designing fault-tolerant API services",font_name:"Inter",font_size_in_px:24,text_color:"#94A3B8",position:{x:80.0,y:360.0},dimensions:{width_in_px:1040,height_in_px:80},},{index:3,type:"text",text:"iterationlayer.com",font_name:"Inter",font_size_in_px:20,text_color:"#6366F1",position:{x:80.0,y:530.0},dimensions:{width_in_px:400,height_in_px:40},},],});awaitBun.write("result.png",Buffer.from(result.data.buffer,"base64"));
importbase64fromiterationlayerimportIterationLayerclient=IterationLayer(api_key="YOUR_API_KEY")result=client.generate_image(dimensions={"width_in_px":1200,"height_in_px":630},output_format="png",layers=[{"index":0,"type":"solid-color-background","hex_color":"#0F172A",},{"index":1,"type":"text","text":"Building Scalable APIs with Elixir","font_name":"Inter","font_size_in_px":48,"text_color":"#FFFFFF","font_weight":"Bold","position":{"x":80.0,"y":120.0},"dimensions":{"width_in_px":1040,"height_in_px":200},},{"index":2,"type":"text","text":"A practical guide to designing fault-tolerant API services","font_name":"Inter","font_size_in_px":24,"text_color":"#94A3B8","position":{"x":80.0,"y":360.0},"dimensions":{"width_in_px":1040,"height_in_px":80},},{"index":3,"type":"text","text":"iterationlayer.com","font_name":"Inter","font_size_in_px":20,"text_color":"#6366F1","position":{"x":80.0,"y":530.0},"dimensions":{"width_in_px":400,"height_in_px":40},},],)withopen("result.png","wb")asf:f.write(base64.b64decode(result["data"]["buffer"]))
packagemainimport("encoding/base64""os"il"github.com/iterationlayer/sdk-go")funcmain(){client:=il.NewClient("YOUR_API_KEY")result,err:=client.GenerateImage(il.GenerateImageRequest{Dimensions:il.Dimensions{WidthInPx:1200,HeightInPx:630},OutputFormat:"png",Layers:[]il.Layer{il.NewSolidColorBackgroundLayer(0,"#0F172A"),il.NewTextLayer(1,"Building Scalable APIs with Elixir","Inter",48,"#FFFFFF",il.Position{X:80.0,Y:120.0},il.Dimensions{WidthInPx:1040,HeightInPx:200}),il.NewTextLayer(2,"A practical guide to designing fault-tolerant API services","Inter",24,"#94A3B8",il.Position{X:80.0,Y:360.0},il.Dimensions{WidthInPx:1040,HeightInPx:80}),il.NewTextLayer(3,"iterationlayer.com","Inter",20,"#6366F1",il.Position{X:80.0,Y:530.0},il.Dimensions{WidthInPx:400,HeightInPx:40}),},})iferr!=nil{panic(err)}decoded,_:=base64.StdEncoding.DecodeString(result.Data.Buffer)os.WriteFile("result.png",decoded,0644)}